I want to read the message which is there in Alert.
Example: If a alert shows "Wrong E-mail address". How to read it? Means i want to store that message in a string.
How to click on OK inside Alert...??
How to do it using Selenium ?
To click on the Ok button on alert, first of all we have to switch to alert with switchTo(). alert() method. Next, to click on the Ok button, we have to use accept() method.
It is a pop-up window that comes up on the screen. There are many user actions that can result in an alert on the screen. For example, if you click on a button that displays a message or maybe when you entered a form, HTML page asked you for some extra information. This is an alert.
I am assuming you are using the 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, take a look this webpage.
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