I have a Modal Dialog like this:
And I want to click on OK button to save this text. So I use switchTo to switch to this dialog:
webDriver.switchTo().frame(0);
I assumed since there is only one Dialog, so I used frameID = 0. But I don't know how to proceed forward from here or how to click on the OK button, because I don't get any HTML info.
Any help much appreicated
Selenium uses the Actions class to perform the right click action. The contextClick() is a method under Actions class to do the right click and once the menu opens, we can select an option from them via automation.
An alert can be of three types – a prompt which allows the user to input text, a normal alert and a confirmation alert. By default, the webdriver can only access the main page, once an alert comes up, the method switchTo(). alert() is used to shift the focus webdriver control to the alert.
It looks like not frame. If it is frame then you can insect those buttons. So are you able to inspect those buttons? if not then it is alert which is cased by javascript. Use switch to alert here
Alert alert = driver.switchTo().alert();
alert.accept(); // for OK
Thank You, Murali
Hi thats not frame that's alert and there is Alert method defined in selenium for performing action :Below are the various operations that you can perform on alerts (for more operations look official documentation)
// working with alerts.
Alert alert = driver.switchTo().alert();
// for clicking on ok button
alert.accept();
// for clicking on cancel button
alert.dismiss();
// for getting alert text message
alert.getText();
// for sending some text inside the alert
alert.sendKeys("alert string");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With