4

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.

4
  • 1
    Possible duplicate of How to handle authentication popup with Selenium WebDriver using Java Commented Jul 18, 2017 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. Commented Jul 19, 2017 at 7:29
  • 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. Commented Jul 19, 2017 at 13:18
  • 1
    Possible duplicate of Selenium - Other way to basic authenticate than via url Commented Nov 21, 2017 at 3:35

4 Answers 4

4

Try getting the URL like this...

driver.get("http://username:[email protected]");

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")
Sign up to request clarification or add additional context in comments.

3 Comments

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?
I have updated code to c#. before it was java which had slightly different syntax.
Thanks Cavan, I tried with driver.Navigate().GoToUrl("username:[email protected]") with some tricks and I am able to handle the authentication alert window.
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.

1 Comment

Thanks @smith9234 for your reply. I tried driver.Navigate().GoToUrl("username:[email protected]"‌​) with some tricks and able to handle the authentication dialog box.
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

Comments

0

Here is a simple approach to overcome this issue:

baseUrl = "http://" + username + ":" + password + "@" + url;
driver.get(baseUrl + "/");

Using the code above we are providing credentials in the URL, while running the script this will bypass the authentication window successfully.

Refer to the below code for how it is done just after the browser is launched:

WebDriver driver = new FirefoxDriver();
String baseUrl = "http://" + "USERNAME" + ":" + "PASSWORD" + "@" + "xyz.com";
driver.get(baseUrl + "/");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.