4

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.

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

2 Answers 2

4

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.

answered Mar 5, 2014 at 14:27
1
  • @Swap if you are satisfied with this answer, please click the check button to indicate that you've accepted it. Commented Mar 5, 2014 at 15:01
0

Look at the given link for example:

  1. How To Handle JavaScript Confirm Box

  2. How To Handle JavaScript Alert Box

alecxe
11.4k11 gold badges52 silver badges107 bronze badges
answered Nov 5, 2014 at 7:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.