2

I am writing an automation script for Chrome browser in selenium web driver using C#. I got stuck in a scenario where multiple tabs are getting open in the same browser and I need to navigate to the first Tab of a browser and need to re-enter the login credentials in the authentication dialog box.

Please find the below screenshot for authorization window:

enter image description here

I am unable to navigate to the first tab and unable to pass the username & password. I found some answers in the Stackoverflow and tried in my script but nothing went right. Here is my sample code:

WebDriverWait wait = new WebDriverWait(driver, 10);
IAlert alert = wait.Until(ExpectedConditions.AlertIsPresent());
alert.SetAuthenticationCredentials(username, pwd);

After executing the above code, the following error is coming:

WebDriverWait has some invalid arguments. Argument '2': cannot convert from 'int' to 'System.TimeSpan'

Is there any specific code for Chrome browser? I am using Visual studio 2008.

Ashish Sharma
  • 121
  • 1
  • 3
  • 19
  • 1
    Possible duplicate of [How to handle authentication popup with Selenium WebDriver using Java](https://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver-using-java) – JeffC Jul 18 '17 at 18:25
  • As I mentioned that i searched some threads in Stackoverflow but it did not work in my script. So there is no point to mark it duplicate. – Ashish Sharma Jul 19 '17 at 07:29
  • See: [How do I do X?](https://meta.stackoverflow.com/questions/253069/whats-the-appropriate-new-current-close-reason-for-how-do-i-do-x) The expectation on SO is that the user asking a question not only does research to answer their own question but also shares that research, code attempts, and results. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! See also: [ask] – JeffC Jul 19 '17 at 13:17
  • You mentioned it but you didn't provide any details. Until you do some research and actually provide details that demonstrate how the solutions provided elsewhere don't work here and the results, it hasn't been proven that it's *not* a duplicate. – JeffC Jul 19 '17 at 13:18
  • 1
    Possible duplicate of [Selenium - Other way to basic authenticate than via url](https://stackoverflow.com/questions/45345882/selenium-other-way-to-basic-authenticate-than-via-url) – undetected Selenium Nov 21 '17 at 03:35

3 Answers3

3

Try getting the URL like this...

driver.get("http://username:password@www.domain.com");

Using the Alert class like this post here(How to handle authentication popup with Selenium WebDriver using Java) apparently only works in IE.

        WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
        IAlert alert = wait.Until(ExpectedConditions.AlertIsPresent());
        alert.SetAuthenticationCredentials("username", "password")
Cavan Page
  • 505
  • 2
  • 12
  • Hi Cavan thanks for your reply, I tried your line of code but it gave me an error. WebDriverWait wait = new WebDriverWait(driver, 10); IAlert alert = wait.Until(ExpectedConditions.AlertIsPresent()); alert.SetAuthenticationCredentials(UserLogin.username, UserLogin.pwd); - Error "Argument '2': cannot convert from 'int' to 'System.TimeSpan'". Is there any specific code for Chrome browser? – Ashish Sharma Jul 19 '17 at 07:42
  • I have updated code to c#. before it was java which had slightly different syntax. – Cavan Page Jul 19 '17 at 14:47
  • Thanks Cavan, I tried with driver.Navigate().GoToUrl("http://username:password@www.domain.com") with some tricks and I am able to handle the authentication alert window. – Ashish Sharma Jul 21 '17 at 11:22
0

Take a look at this tutorial, http://toolsqa.com/selenium-webdriver/autoit-selenium-webdriver/

I have done this using Java, I am assuming you can use the AutoIt dlls for C# in the same manner.

smit9234
  • 361
  • 1
  • 7
  • Thanks @smith9234 for your reply. I tried driver.Navigate().GoToUrl("username:password@www.domain.com"‌​) with some tricks and able to handle the authentication dialog box. – Ashish Sharma Jul 21 '17 at 11:23
0

Yet another approach: write chrome extension that'll listen on chrome.webRequest.onAuthRequired and will provide credentials.

Doc: https://developer.chrome.com/extensions/webRequest#event-onAuthRequired

matemaciek
  • 603
  • 7
  • 11