简体   繁体   中英

Browser Alert In Selenium WebDriver

如何在代码中禁用浏览器的Alert Box,我的意思是我不希望chromedriver由于任何原因弹出警报。

You can set window.alert(...) to another function (eg log to console)

WebDriver driver = createDriver();
driver.get("http://foo.bar.com");
if (driver instanceof JavascriptExecutor) {
    String script = "window.alert = function(message) { console.log(message); };";
    ((JavascriptExecutor) driver).executeScript(script);
}
driver.findElement(By.id("someButton")).click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM