Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Message From Alert and click on OK

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 ?

like image 821
Ranadheer Reddy Avatar asked May 17 '12 10:05

Ranadheer Reddy


People also ask

How do you click on the OK button of the alert?

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.

What is difference between alert and popup?

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.


1 Answers

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.

like image 147
Ranhiru Jude Cooray Avatar answered Oct 22 '22 05:10

Ranhiru Jude Cooray