I'm new to sele开发者_如何转开发nium, i'm trying to do basic programming for login page, when i enter a wrong password i get pop up box saying invalid password or username with ok button, but selenium RC is not recognizing that pop up window, how do i code that selenium would recognize that. This is the code ive used,
public void nlogin()
{
selenium.Open("/login.aspx");
selenium.Type("Login1_UserName", "abcd");
selenium.Type("Login1_Password", "welcome");
try
{
selenium.Click("Login1_LoginButton");
Assert.AreEqual("ok", selenium.GetAlert());
selenium.WaitForPopUp("ok", "3000");
selenium.Click("ok");
}
catch (Exception)
{
}
}
Please help me with regards to this.
use selenium.getAlert()
it will return the string contained in the JavaScript alert.
WaitForPopUp()
is not for alert boxes it's for new browser windows.
You also do not need the Click()
to press the ok button on the alert box, the GetAlert()
does this for you.
Your code should read:
public void nlogin()
{
selenium.Open("/login.aspx");
selenium.Type("Login1_UserName", "abcd");
selenium.Type("Login1_Password", "welcome");
selenium.Click("Login1_LoginButton");
Assert.AreEqual("ok", selenium.GetAlert());
}
Also GetAlert()
gets the content of the alert box, surely this is some kind of warning message rather than the text "ok".
You may want to look through the NDoc documentation for selenium which can be found here
精彩评论