在使用selenium 2.4.0之前,我使用了以下代码:
alert = page.driver.browser.switch_to.alert
if alert.text
....
end
Run Code Online (Sandbox Code Playgroud)
Selenium 2.4.0包含更改"*当没有警报时在switch_to.alert中提升.",所以我得到一个No alert is present (Selenium::WebDriver::Error::NoAlertOpenError)例外.
如何使用selenium-web-driver 2.4.0检查是否存在警报?
我目前正在协助使用Selenium 2/WebDriver和C#对使用InternetExplorerDriver的ASP.NET MVC应用程序进行概念验证.
应用程序使用标准模式通知用户记录已保存.这可以通过设置TempData来包含"Record saved successcessefully",如果View中存在TempData,视图将提醒消息.
在针对此功能进行Selenium测试时,我们从以下C#/ Selenium测试代码中获得了不一致的行为:
_driver.Navigate().GoToUrl(_baseUrl + "/Amraam/List");
_driver.FindElement(By.LinkText("Create New")).Click();
_driver.FindElement(By.Id("txtAmraamSerialNumber")).SendKeys("CC12345");
var selectElement = new SelectElement(_driver.FindElement(By.Id("LocationId")));
selectElement.SelectByText("Tamworth");
_driver.FindElement(By.Id("btnSave")).Click();
var wait = new WebDriverWait(_driver, defaultTimeout);
IAlert alert = wait.Until(drv => drv.SwitchTo().Alert());
_alertText = alert.Text;
alert.Accept();
Assert.That(_alertText, Is.EqualTo("Record successfully saved"));
Run Code Online (Sandbox Code Playgroud)
大约50%的时间,Selinium将失败
OpenQA.Selenium.NoAlertPresentException:没有警报处于活动状态
我很难找到复制问题的确切方法,并担心不一致方面.如果它一直失败,那么我们可以调试并跟踪问题.
有谁知道如何禁用它?或者如何从已自动接受的警报中获取文本?
这段代码需要工作,
driver.findElement(By.xpath("//button[text() = \"Edit\"]")).click();//causes page to alert() something
Alert alert = driver.switchTo().alert();
alert.accept();
return alert.getText();
Run Code Online (Sandbox Code Playgroud)
但反而给出了这个错误
No alert is present (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.14 seconds
Run Code Online (Sandbox Code Playgroud)
我正在使用FF 20和Selenium 2.32
我正在努力写一个测试; 我想检查是否存在警报,检查其文本是否存在并接受它.
我检查了如何在Selenium webdriver中等待警报?,如何使用WebDriver检查是否存在警报?和selenium 2.4.0,如何检查是否存在警报,但我无法使用https://github.com/admc/wd进行调整
我写过一些东西
browser.alertText(function (err, text) {
if (text) {
browser.acceptAlert(function () {
// ...
});
}
});
Run Code Online (Sandbox Code Playgroud)
显示警报时效果非常好,但alertText没有警报窗口时会挂起.
如何在发布之前检查警报是否存在alertText?
谢谢你的帮助,