Easy approach to handle authentication window in selenium webdriver
Before we get started, on how to handle authentication window in Selenium WebDriver. Let’s discuss what authentication window is & why it is used in applications?
What is Authentication Window?
Authentication is a process which is required to access some applications in which HTTP authentication is used for security purpose. These are server side validations which ask for authentication beforehand user can access an application. Also, known as basic authentication in `web applications where the browser window is used to get user credentials. The handling of pop up window came into the picture because of security and minimizing the unauthorized users in the application.
While automating an application testing through selenium, this issue is generally faced by some of us. I have checked this in many other websites talking about handling pop up window using the installation of AutoIt Tool, Add-ons like AuthAuth etc.
Why is this issue encountered?
Let’s discuss more closely why this issue is encountered? While running the automated script on the website it locates the elements using the ‘FindElement’ method. Since authentication protected applications restricts the user to access the web elements. We simply append username and password in the web application URL, so that it allows the script to access locators.
What’s the solution?
Here is a simple approach to overcome this issue. This can be easily handled using the piece of code below:
baseUrl=”http://” + username + “:” + password + “@” + url;
driver.get(baseUrl + “/”);
Using code above we are providing credentials in URL which will add username & password in URL ), while running the script it will bypass the authentication window successfully
Refer syntax in how it is done just after browser is launched:
WebDriver driver = new FirefoxDriver();
String baseUrl=”http://” + “USERNAME” + “:” + “PASSWORD” + “@” + “xyz.com”;
driver.get(baseUrl + “/”);
Hope the above solution works. Please let me know if you have any queries/ additions in the comment box below.
Happy Testing!!
whenever i try to login into the application with selenium automation code it again redirects me to the same login page. Need Help !!!!1
Hi,
How to handle zscaler security in chrome browser.
Suppose I want to automate https://google.com but what happend it redirects to zscaler security page and we need to provide id and password manuaaly then it redirects to google and throws an exception NoSuch Element Exception.
Please help?
Hi,while Uploading folder in Latest Chrome browser,it is throwing alert>>How can we handle this alert.
Tried with Alert().switchto().alert().accept.This is not working in this case.can you please try and help me.
Same alert can observed in Google drive.Try to upload folder in Google drive>>then you can observe one alert as”Only do if you trust this site”
The above code is not working for URL with https://.Any help in this is highly appreciated.
Will this work in windows 10 ?
How to handle @ in password
While entering username in the format test.test, I am getting error message as :
You are about to log in to the site “bca-csr-ui.int.bell.ca” with the user name “samar%2Eghosh”, but the web site does not require authentication. This may be an attempt to trick you.
thanks its helped me alot but only problem with ie
wow, it works, Thanks a ton !!
How to handle if the user name is like “test\123” ?
how would you handle the ‘\’ in the username ?
good question!
same issue for me as well..how did you handle this can you please tell me
I am having problem as after enter the login credentials and password, and Click on Login that time the Windows Authentication popup is coming
I do have a question..
If the user authentication is asked randomly during navigation within the website, then how do I handle it..
This doesn’t work with the later version of browsers as it is against the new W3C compliance. If you feel otherwise, please share the browser name and the latest version which you tested this approach against.
Also, how would you handle the ‘@’ in the password ? Did you think about it?