How to handle the javascript alert using webdriver with IEDriver

别等时光非礼了梦想. 提交于 2019-12-12 00:40:11

问题


With the selenium IEwebdriver, the webdriver Alert class methods are not working ... This issue seems specific to the IE browser, while in chrome,ff etc this works well.

Any workarounds that we can use to handle the js alerts using IEWebdriver ..?

I tried with the javascriptexecutor method too as below

((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; }");

But no luck :(

Any help is highly appreciated


回答1:


In java we do it like this:

WebDriverWait wait = new WebDriverWait(driver, TIMEOUT);
wait.until(ExpectedConditions.alertIsPresent());

Above code will implicitly wait for an alert. It will throw a TimeoutException if alert is not present.

driver.switchTo().alert().accept();

Above code switches to alert popup and clicks OK. If alert is not present then it will throw NoAlertPresentException.

Hope it helps.



来源:https://stackoverflow.com/questions/19020468/how-to-handle-the-javascript-alert-using-webdriver-with-iedriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!