By Harshavardhan Konakanchi

2012-05-01 08:47:42 8 Comments

Does anyone know about handling Browser Authentication using Selenium or any other tool during automation?


@LKTS 2019-01-31 11:08:12

with Chrome 70 and other versions :

http://username:[email protected]/yourpage

@LKTS 2019-02-05 12:47:15

agree, but as firefox context was explicit, thought worth rescoping too...

@Jack Wilson 2018-05-31 09:58:42

you can use auto IT script to handle this problem

WinWaitActive("[CLASS:Chrome_WidgetWin_1]", "", time)

@Yoav Levinger 2015-10-18 14:46:22

All the hacks via auto-it, sikuli, etc. just wasting your time when you'll run it in your CI solution, using several browser types / OS / Version / Resolutions etc.

The way to do it correctly is to identify the authentication actual method and perform a login using Rest protocol for instance.

I used it to get the JSESIONID cookie and insert it to the selenium driver. hint on that: go to a non-exiting url of the domian first, then set the cookie, then go to the required url - you are logged-in.

use: rest client authentication to get the JSESSION ID

and With this information:


//the information got from the rest client login:
Cookie cookie = new Cookie(name, value, domain, path, expiry, isSecure, isHttpOnly);

try {
} catch (Exception e) {


@Chandra Shekhar 2016-09-30 13:09:03

Can you describe what a 'non-exiting-url' is?

@Roman 2016-07-05 12:54:48

Everything I have read on the Web didn't help me. So before making a request, like this:


you have to run a new thread like this:

RunScript runScript = new RunScript();

In this case you are free to input login and password on another thread of follwing class

public class RunScript extends Thread {

public void run() {
    try {
        File file = new File("D:\\jacob-1.18-x86.dll");
        System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
        AutoItX autoIt = new AutoItX();
        autoIt.winActivate("yourWindowName", "");
        if (autoIt.winExists("yourWindowName")) {
            autoIt.send("username{TAB}", false);
            autoIt.send("password{Enter}", false);
    } catch (InterruptedException ex) {

@fra_jo 2016-09-29 03:25:49

I spent days on this - literally. Trying to get past browser level authentication within my company network to hit an application. The solution was to use the 'unsername:[email protected]' component within the URL, BUT to add a forward slash at the end of the login URL.

So total login URL looks like this (note the '/' after yourpage):

http://username:[email protected]/yourpage/

Works with Watir, Capybara and Selenium Webdriver.

@Alex Punnen 2012-11-23 12:20:18

You can use Java Robot class with Selenium 2 /Selenium WebDriver using Firefox

WebDriver driver = new FirefoxDriver();

    WebElement myDynamicElement = driver.findElement("app"));

    Alert alert = driver.switchTo().alert();

    try {
        Robot robot = new Robot();

        robot.keyPress(KeyEvent.VK_TAB);//go to password feild



        } catch (AWTException e) {


Using Selenium with Robot

@Petr Janeček 2012-05-01 11:29:40

EDIT in 2015:

This answer is outdated. WebDriver nowadays supports authentication! See How to handle authentication popup with Selenium WebDriver using Java

Original answer:

This is not handled very well by Selenium.

You can try using http://username:[email protected]/yourpage

instead of just

However, as far as I know, Firefox will still pop up a browser dialog requesting a confirmation.

You can try Robot if you're using Java (or any similar tool like AutoIt).

You could use driver.manage().addCookie() if you're using WebDriver.

Or a custom FirefoxProfile that has already passed the authentication once.

@Petr Janeček 2012-05-15 11:59:00

Out of curiosity, which path did you take in the end, what was your solution?

@Harshavardhan Konakanchi 2012-05-15 15:45:01

@Justin 2013-09-30 14:43:54

This posting contains some very relevant information to bypass NTLM browser authentication using Selenium:…

@Tatarin 2015-01-16 16:16:30

What will solution 3 do? the one with cookies?

@Petr Janeček 2015-01-16 16:30:39

@Timur Sorry, this answer is old, WebDriver nowadays supports authentication! See…

@Petr Janeček 2015-01-16 16:36:45

Yes. See that's what's used in the link I put into my last comment,.

Related Questions

Sponsored Content

75 Answered Questions

[SOLVED] How do you disable browser Autocomplete on web form field / input tag?

31 Answered Questions

[SOLVED] Git push results in "Authentication Failed"

28 Answered Questions

14 Answered Questions

45 Answered Questions

[SOLVED] How to take screenshot with Selenium WebDriver

17 Answered Questions

[SOLVED] What is the maximum length of a URL in different browsers?

  • 2009-01-06 16:14:30
  • Sander Versluys
  • 1252355 View
  • 4837 Score
  • 17 Answer
  • Tags:   http url browser

4 Answered Questions

10 Answered Questions

[SOLVED] Use basic authentication with jQuery and Ajax

Sponsored Content