Thursday, July 22, 2010

Deal with JS div DialogPane in WebDriver

Updated: Another related post on js alert and confirmation stuff on http://joychester.blogspot.com/2010/08/deal-with-javascript-alert-and-confrim.html

During my testing, I met one "Send" link which will trigger js DialogPane to get your confirmation, such "OK" or "Cancel", onclick will execute JavaScript function like this for "OK" :

onclick="confirmSend()"

Here is a sample code how I simulate clicking "OK" within the js DialogPane:

driver.switchTo().activeElement();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("confirmSend()");


Thanks for Shawn's Demo code, she gives me really great suggestion and inspiration!! :)

2 comments:

  1. Hi Cheng,

    Thanks for this information... HOwever i have one more question.. does webdriver support default dialog handlers for all types of alerts and dialog boxes?? if not then how can we do this with current implementation of webdriver..

    I have been using WATIN for web automation and it has default dialog handlers since i am new to Webdriver.. eager to know if there is any such alert handling is provided by tool itself..

    ReplyDelete
  2. Hi,
    Unfortunately, there is no such a default method to handle alerts and dialog boxes, I am looking for this fix too, it will be in beta release according to their road map.

    ReplyDelete