Webdriver - HTTP authentication dialog Webdriver - HTTP authentication dialog selenium selenium

Webdriver - HTTP authentication dialog


The problem is that this is not a javascript popup hence you cannot manipulate it via selenium's alert().

If both AutoIt and submitting credentials in the URL (the easiest option - just open up the url and click "Display Image") are not options for you, another approach could be to use AutoAuth firefox addon to automatically submit the previously saved credentials:

AutoAuth automatically submits HTTP authentication dialogs when you’ve chosen to have the browser save your login information. (If you’ve already told the browser what your username and password are, and you’ve told it to remember that username and password, why not just have it automatically submit it instead of asking you each time?)

Following the answer suggested in HTTP Basic Auth via URL in Firefox does not work? thread:

  • Install AutoAuth Firefox plugin;
  • Visit the site where the authentication is needed. Enter your username and password and make sure to choose to save the credentials;
  • Save AutoAuth installation file at your hard drive: at the plugin page, right click at “Add to Firefox” and “Save link as”;
  • Instantiate Firefox webdriver as following:
FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("default");File pluginAutoAuth = new File("src/test/resources/autoauth-2.1-fx+fn.xpi");firefoxProfile.addExtension(pluginAutoAuth);driver = new FirefoxDriver(firefoxProfile);

Also, in a way similar to AutoIt option - you can use sikuli screen recognition and automation tool to submit the credentials in the popup.


Also see other ideas and options:


The Basic/NTLM authentication pop-up is a browser dialog window. WebDriver (Selenium 2.0) cannot interact with such dialog windows. The reason for this is because WebDriver aims solely at mimicking user interaction with websites, and browser dialog windows are currently not in that scope. JavaScript dialog windows, are part of the website, so WebDriver can handle those. In Selenium 1.0 it is possible to do basic authentication.

So how to solve this issue? 1) Authentication via URL http://username:password@website.com 2) Use a browser plugin that will handle the Basic/NTLM autentication 3) Use a local proxy that will modify the request header and pass along the username/password and 4) Make use of a robot, like AutoIt, or some Java library.

Option 1: is the easiest and has the least impact on the system/test. Option 2: has a high browser impact as your loading plugins. Also every browser uses its own plugin and it's possible that the required plugin for a certain browser is not available. Option 3: Works well with HTTP, but HTTPS requires custom certicates thus not always an option. Not much impact on both system and test. Option 4: Mimics keyboard presses, its a go to solution but prone to errors. Only works when the dialog window has focus and it is possible that this is not always the case.


I faced same issue, and got some concrete solution using robot class. Its workaround or solution, Let see , but it works.

public class DialogWindow implements Runnable {@Overridepublic void run() {    try {        entercredentials();    } catch (InterruptedException e) {        // TODO Auto-generated catch block        e.printStackTrace();    }}public void entercredentials()  InterruptedException {    Thread.sleep(5000);    try {        enterText("username");        enterSpecialChar(KeyEvent.VK_TAB);        enterText("password");        enterSpecialChar(KeyEvent.VK_ENTER);    } catch (AWTException e) {    }}private void enterText(String text) throws AWTException {    Robot robot = new Robot();    byte[] bytes = text.getBytes();    for (byte b : bytes) {        int bytecode = b;        // keycode only handles [A-Z] (which is ASCII decimal [65-90])        if (bytecode> 96 && bytecode< 123)            bytecode = bytecode - 32;        robot.delay(40);        robot.keyPress(bytecode);        robot.keyRelease(bytecode);    }}private void enterSpecialChar(int s) throws AWTException {    Robot robot = new Robot();    robot.delay(40);    robot.keyPress(s);    robot.keyRelease(s);}}

How to call it

WebDriver driver= new FirefoxDriver()// or any other driver with capabilities and other required stuff(new Thread(new DialogWindow())).start();driver.get(url);