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.

  • 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, 2014 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, 2014 at 14:11
  • selenium 4 can now help you with basic authentication selenium.dev/blog/2021/a-tour-of-4-authentication Jul 12, 2023 at 20:54

2 Answers 2


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.

  • @Swap if you are satisfied with this answer, please click the check button to indicate that you've accepted it.
    – user246
    Mar 5, 2014 at 15:01

Look at the given link for example:

  1. How To Handle JavaScript Confirm Box

  2. How To Handle JavaScript Alert Box

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.