Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to navigate the command on the alert box, but I am not able to do it in Web Driver with JAVA. Please help me with it. Apart from this I would also like to know how to tackle with the confirmation box and Warnings prompts displayed.

share|improve this question
Could you give us a bit more information to go by, please? How have you tried to access the alert box? What is the failure message? What's the code of the page generating the alert? Right now there isn't enough information for the Selenium folks to give you much help. – Kate Paulk Mar 5 '14 at 12:05
There is several different types of alerts. There can be pop up alerts, iframe alerts and many many other ways to alert the end user. The way that the alert is displayed will change the way that the alert is handled. – Paul Muir Mar 5 '14 at 14:11
up vote 4 down vote accepted

If this is a Javascript alert box, this is relatively straightforward; you can switch to it with driver.switchTo().alert(); in Java. If you save the return value of that as an Alert object, you can interact with it, like alert.accept(). See the javadoc for more information.

Since you're asking, however, I suspect it's not so simple. If this is not really an alert, but a popup that the browser has generated, such as a Basic Authentication prompt, you cannot interact with it using WebDriver, as WebDriver can only interact with things that exist in the DOM. You will have to use another Java library, such as Robot, to interact with popups at this level.

share|improve this answer
Thanks Yamikuronue... – Swap Mar 5 '14 at 14:30
@Swap if you are satisfied with this answer, please click the check button to indicate that you've accepted it. – user246 Mar 5 '14 at 15:01

Look at the given link for example-

  1. How To Handle JavaScript Prompt Box:

  2. How To Handle JavaScript Confirm Box:

  3. How To Handle JavaScript Alert Box: http: //

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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