7

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:
http://code.google.com/p/selenium/issues/detail?id=27

The following blog post attempts to address a few related issues:
http://seleniumdeal.blogspot.com/2010/04/working-with-modal-dialogs-and-selenium.html

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.

3

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. – Michael Yang Jun 9 '11 at 12:57
  • Before calling driver.get(), one could create a second thread to interact with the blocking dialog. – user246 Jun 9 '11 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. – Suchit Parikh Jun 9 '11 at 18:38
1

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. – Michael Yang Jun 9 '11 at 12:53
  • I cant find anything in the documentation that limits it to html. in the selenium.org – Theo Jun 10 '11 at 8:04
1

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):

driver.switchTo().alert().accept();

More info about this methods here

0
  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, privacy policy and cookie policy

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