Close ok button in popup with Selenium Driver

Asked

Viewed 1,609 times

2

I am developing a test tool using Java driver Selenium.

The portal I’m testing presents a pop-up or a dialog box, where it has an OK button. My tool needs to press. clik() on this button,I cannot select the id of the button as I cannot use F12 or xpath to identify the html of the pop-up.

I found this code, but without identifying the id of the button his action is not exercised.

driver.switchTo().window("[handle da sua janela]");
driver.close();

insira o código aqui// Or click on the path of the ok button

What can I do?

1 answer

1

whereas it is only a warning you can simply do the following:

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

you can call the Dismiss() method too, if for example it is one of those options with OK/Cancel, then Accept() in this case would click on ok and Dismiss() on Cancel.

  • Thanks, @Lucas, I had already managed to revolve, but I didn’t know the Dismiss(), now I’ve learned one more command.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.