Easy approach to handle authentication window in selenium webdriver

04 / Feb / 2016 by Shilpa Ranjan 6 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 ), 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!!



comments (6)

  1. Deepak Rane

    I am having problem as after enter the login credentials and password, and Click on Login that time the Windows Authentication popup is coming

  2. surya teja

    I do have a question..
    If the user authentication is asked randomly during navigation within the website, then how do I handle it..

  3. Hifzur

    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?


Leave a comment -