tags:

views:

105

answers:

1

how to dismiss a alert box by clicking "OK" button? I saw on WebDriver Google group that Simon is adding this feature. I am not sure whether this is supported or not.

+1  A: 

Take a look at issue 27 in the Google Code Issues List. Use the JavascriptExecutor to override the browser's alert:

((JavascriptExecutor)driver).executeScript("window.alert = function(msg){};");

It's a similar solution to handle confirmation dialogs.

((JavascriptExecutor)driver).executeScript("window.confirm = function(msg){return true;};");

This is a pretty popular request so hopefully it'll get iplmemented soon. The downside to these approaches is it's not easy to validate the text in the message. You may want to step down to Selenium to do that.

pnewhook
I have tried `((JavascriptExecutor)driver).executeScript("window.confirm = function(msg){return true;};");` but no luck. Seems like no one has a reliable workaround. I really hope they can get this done soon. Thanks anyway.
zihaoyu
Double check that your driver refers to the correct page/frame. I've successfully run this so it must be something unique with your page, not the code.
pnewhook