I am working on the test automation that uses WebDriver (Selenium 2) and Java. The AUT is web-based application. A modal dialog pops up that requires user authentication before the user can access the Web app's login page.

I have searched extensively and am unable to get any working solution.

Relevant Search results
The following thread addresses how to handle alerts and prompts:

The following blog post attempts to address a few related issues:

But neither of them provides an implemented solution to the problem.

What's happening:
When driver.get("login page") is executed, the browser attempts to open the page, but a modal dialog appears which asks for the user authentication (login & pwd). The WebDriver keeps waiting until I manually authenticate or click Cancel.

The execution never goes to the next step. So whatever I attempt after "driver.get()" is never executed until manual intervention.

Note: I am using Firefox 4

EDIT: The blocker to all the solutions is to the following - (from WebDriver's get() method's documentation: This is done using an HTTP GET operation, and the method will block until the load is complete for driver.get(). Due to this block, the control of execution never goes to the next step i.e. Any statement written after the driver.get() will not get executed until load is complete.

  • This thread is dedicated to supporting "timeout on page load": code.google.com/p/selenium/issues/detail?id=687 Jun 8, 2011 at 22:29
  • Have you considered finessing the problem by passing the username/password in an HTTP request or setting the appropriate cookie?
    – user246
    Jun 9, 2011 at 13:15

4 Answers 4


There is a java.awt.Robot class for interacting with non-HTML dialogs. I've used that for dealing with file dialogs and download dialogs.

  • That's one of the solutions in selenium 1. The other is using AutoIt scripts. I haven't dived into seleninum 2 (webdriver) very much. The point in this issue is where to inject the condition checkings for the presence of the modal dialog, as the webdriver.get() is not asynchronous. Any code after the method are not executed until get() returns. So setting a timeout and catching it for dialog checking could be one option. Jun 9, 2011 at 12:57
  • Before calling driver.get(), one could create a second thread to interact with the blocking dialog.
    – user246
    Jun 9, 2011 at 14:07
  • @Michael - Setting a timeout doesn't really work as this feature is faulty in WebDriver (selenium issue id # 687). @user246 - I will attempt your approach and comment back how it works out. Jun 9, 2011 at 18:38

I use a waitfortextpresent command in selenium IDE in similar cases. so that it will wait for a text on the modal dialog and enter the credentials on that. Perhaps a similar command might help in webdriver

  • I don't think you can waitfortextpresent in seleniumIDE, unless the dialog you were referring to is a mocked html dialog. Jun 9, 2011 at 12:53
  • I cant find anything in the documentation that limits it to html. in the selenium.org
    – Theo
    Jun 10, 2011 at 8:04

I know I'm gravediging here but here goes anyway:

Selenium 2.X offers mechanism to automaticaly "jump" to modal alert and accept or decline prompt. Code example (JAVA webdriver):


More info about this methods here

  1. if it is JS modal:

You can always switch to selected dialog, work on it, send it. then switch back to previous window.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.