问题
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