Easy approach to handle authentication window in selenium webdriver

04 / Feb / 2016 by Shilpa Ranjan 0 comments

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 (http://username:password@www.xyz.com), 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!!



Leave a comment -