Tim*_*vis 12 c# selenium nunit webdriver selenium-webdriver
我在c#中使用selenium编写了一个nUnit测试.
一切顺利,直到我必须确认一个JS确认框.
这是我正在使用的代码:
this.driver.FindElement(By.Id("submitButton")).Click();
this.driver.SwitchTo().Alert().Accept();
Run Code Online (Sandbox Code Playgroud)
提交按钮后出现确认框.确认出现,然后立即消失,但表单不提交.无论上面的accept()行如何,行为都是相同的.
我使用的是Firefox v15.0.1和selenium v2.24
我尝试在提交点击和确认接受之间放置一个Thread.Sleep.
我读过的所有内容都说selenium驱动程序会自动发送确认信息,但其他内容似乎正在发生.
eug*_*kov 14
在这个问题上,我会尝试验证确认框存在.它是这样的:
this.driver.FindElement(By.Id("submitButton")).Click();
boolean presentFlag = false;
try {
// Check the presence of alert
Alert alert = driver.switchTo().alert();
// Alert present; set the flag
presentFlag = true;
// if present consume the alert
alert.accept();
} catch (NoAlertPresentException ex) {
// Alert not present
ex.printStackTrace();
}
return presentFlag;
}
Run Code Online (Sandbox Code Playgroud)
然后,如果不工作.尝试逐步调试.其他一些有关信息警报(确认框)中硒处理这里 希望这在某种程度上可以帮助你
您只需要:
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29875 次 |
| 最近记录: |