简体   繁体   English

Selenium WebDriver中的浏览器警报

[英]Browser Alert In Selenium WebDriver

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

You can set window.alert(...) to another function (eg log to console) 您可以将window.alert(...)设置为其他功能(例如,登录到控制台)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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