2012-12-10

How to work with JavaScript Alert in Selenium WebDriver

In this article we are going to see the functions needed to control JavaScript pop-up alert messages. I am using c#(CV2010).

After declaring web driver declare the Alart type veritable.
IAlert myAlert;
In the function , initiate myAlert object as
myAlart = driver.SwitchTo().Alert();
Now, this myAlart object can do some work.
-To  Accept the alert
myAlert.Accept();
-To Dismiss the alert
myAlart.Dismiss();
-To Write text in the alert(when needed)
myAlart.SendKeys("string");
-To get the text of the alert
myAlart.Text;
Note : This will provide a string text as output

...Thanks...:)... To be continued...

No comments:

Post a Comment