![](/img/trans.png)
[英]How to handle a javascript alert window using PHP behat/mink selenium2 chrome webdriver
[英]How to handle the javascript alert using webdriver with IEDriver
使用selenium IEwebdriver,webdriver Alert类方法不起作用...这个问题似乎特定于IE浏览器,而在chrome,ff等这很好用。
我们可以用来处理使用IEWebdriver的js警报的任何变通方法..?
我尝试使用javascriptexecutor方法,如下所示
((JavascriptExecutor)driver).executeScript("window.alert = function(msg){return true;};");
((JavascriptExecutor)driver).executeScript("window.prompt = function(msg) { return true; }");
((JavascriptExecutor)driver).executeScript("window.confirm = function(msg) { return true; }");
但没有运气:(
任何帮助都非常感谢
在java中我们这样做:
WebDriverWait wait = new WebDriverWait(driver, TIMEOUT);
wait.until(ExpectedConditions.alertIsPresent());
上面的代码将隐式等待警报。 如果不存在警报,它将抛出TimeoutException。
driver.switchTo().alert().accept();
上面的代码切换到警告弹出窗口并单击确定。 如果不存在alert,则它将抛出NoAlertPresentException。
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.