Is there a way to configure Selenium WebDriver so that javascript alerts are always accepted?
I am testing an application that requests the user to confirm deletion from a javascript pop-up alert dialog.
I would like it so that alerts are always accepted automatically.
I found a workaround.
inject javascript to handle the alert / confirms yourself (although you'll need to do this after every page refresh before the alert shows up and you won't be able to handle alerts that are onload)
( (JavascriptExecutor) driver ).executeScript("window.alert = function(){}");
or
(JavascriptExecutor) driver ).executeScript("window.confirm = function(){return true;}");
https://github.com/detro/ghostdriver/issues/20#issuecomment-13621554
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.