How to handle browser authentication in Chrome using Selenium Webdriver (C#)?
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")
Related videos on Youtube
Ashish Sharma
I am an Asst. Manager Software Testing and also have good hand-on experience in .NET Framework C#. Area of expertise: 1. .Net Framework C# 2. SQL Server 2005, 2008 3. Manual Testing 4. Basic knowledge of JAVA, C++, & QTP.
Updated on June 04, 2022Comments
-
Ashish Sharma almost 2 years
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:
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.
-
JeffC almost 7 yearsPossible duplicate of How to handle authentication popup with Selenium WebDriver using Java
-
Ashish Sharma almost 7 yearsAs 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.
-
JeffC almost 7 yearsSee: 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: How to Ask
-
JeffC almost 7 yearsYou 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.
-
undetected Selenium over 6 yearsPossible duplicate of Selenium - Other way to basic authenticate than via url
-
-
Ashish Sharma almost 7 yearsHi 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?
-
Cavan Page almost 7 yearsI have updated code to c#. before it was java which had slightly different syntax.
-
Ashish Sharma almost 7 yearsThanks Cavan, I tried with driver.Navigate().GoToUrl("username:[email protected]") with some tricks and I am able to handle the authentication alert window.
-
Ashish Sharma almost 7 yearsThanks @smith9234 for your reply. I tried driver.Navigate().GoToUrl("username:[email protected]") with some tricks and able to handle the authentication dialog box.