阅读来自警报的消息,然后单击确定

Ran*_*ddy 7 selenium selenium-rc

我想阅读Alert中的消息.

示例:如果警报显示"电子邮件地址错误".怎么看?意味着我想将该消息存储在字符串中.

如何单击确定内部警报... ??

如何使用Selenium?

Ran*_*ray 12

我假设您正在使用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();
Run Code Online (Sandbox Code Playgroud)

答案在这里找到.

如果您使用的是Selenium RC,请查看网页.

  • 这是一个更好的链接,我认为(当前主干):http://selenium.googlecode.com/svn/trunk/docs/api/dotnet/html/M_Selenium_ISelenium_GetAlert.htm (3认同)
  • 谢谢@Slanec.我会用你的链接更新我的回答. (2认同)