Jonathan Kittell
Jonathan Kittell

Reputation: 7493

How to check if Windows Modal Dialog is present using Selenium WebDriver

I have a Windows Modal Dialog that appears at times for some tests and then other times it does not appear.

enter image description here

I know when it will possibly show up. I want to be able to grab the window handle of the modal dialog and send the enter key to dismiss it.

Is it possible to detect if a modal dialog is present using the Selenium web driver?

Upvotes: 0

Views: 2187

Answers (2)

Rupesh Shinde
Rupesh Shinde

Reputation: 1956

After we perform the action which opens Modal Dialog box, Try Using Robot class, Used Manual wait of 7 sec though its not good practice, you can change it as per your requirement. See if that works.

Robot robot = new Robot();

Thread.sleep(7000);

robot.keyPress(KeyEvent.VK_ENTER); 

robot.keyRelease(KeyEvent.VK_ENTER);

Upvotes: 0

bcar
bcar

Reputation: 815

If this is a javascripty alert box then

IAlert alert = driver.SwitchTo().Alert();
alert.Accept();

Should be sufficient to acknowledge.

Upvotes: 1

Related Questions