Reputation: 151
How do I disable Alert Box of the browser in the code, I mean I don't want my chromedriver to pop up an alert for any reason, .
Upvotes: 0
Views: 210
Reputation: 27986
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();
Upvotes: 1