Close ok button in popup with Selenium Driver

1

I'm developing a testing tool using selenium driver in java.

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

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

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

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

What can I do?

    
asked by anonymous 22.08.2018 / 14:07

1 answer

0

Considering that it is only an alert 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 that case you would click ok and dismiss () will not cancel.

    
15.09.2018 / 01:00