Read the "From alert" message and click "OK."

I want to read the message that is in Alert.

Example. If the warning shows "Invalid email address." How to read it? I want to keep this message in line.

How to click OK inside the warning ... ??

How to do this using Selenium?

+4
source share
2 answers

I assume you are using Selenium WebDriver.

// Get a handle to the open alert, prompt or confirmation Alert alert = driver.switchTo().alert(); // Get the text of the alert or prompt alert.getText(); // And acknowledge the alert (equivalent to clicking "OK") alert.accept(); 

The answer was found here .

If you are using Selenium RC, check out this web page.

+7
source

I found that in Selenium RC, if you know that a confirmation button will appear, you need to add selenium.getConfirmation(); into your code.

This is how I used it ( Note : I use Java in Eclipse)

 selenium.click("//input[@id=\"accepted-emails\"]"); // Confirmation box after this line if (selenium.isConfirmationPresent()) String confirmationString = selenium.getConfirmation(); // this line is needed selenium.keyPressNative("10"); // to press the OK key selenium.waitForPageToLoad("30000"); System.out.println(confirmationString); // this is not really needed, but used it to simply show the confirmation box message 

Hope this helps!

0
source

Source: https://habr.com/ru/post/1412953/


All Articles