Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click to confirm a Modal Dialog with Selenium WebDriver

I have a Modal Dialog like this: enter image description here

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

like image 490
Ragnarsson Avatar asked Apr 04 '16 16:04

Ragnarsson


People also ask

How do you right click and select Options in Selenium?

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.

What is alert () in driver switchTo ()?

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.


2 Answers

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

like image 177
murali selenium Avatar answered Nov 14 '22 23:11

murali selenium


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");
like image 39
eduliant Avatar answered Nov 15 '22 00:11

eduliant