Not able to click "OK" on Popup !! ( Selenium/Python/Firefox )

278 views
Skip to first unread message

Anand Lambert

unread,
May 17, 2017, 1:34:02 AM5/17/17
to Selenium Users
Hi,

I'm trying to automate a site. In which process I get a popup ( the main window freezes, so Im assuming its a modal dialog popup ) with two buttons [ OK and Cancel ] .. 
I need to find a way to click the "OK" to proceed to the rest of my script.

I'm doing this on Firefox using selenium webdriver and Python.. Kindly help.. Thanks.. 

Xiang Dong

unread,
May 17, 2017, 9:08:53 AM5/17/17
to seleniu...@googlegroups.com

is it a prompt dialog, if yes, you can switch to the alert and accept or cancel it.


If it is a modal window, you main window will be frozen and you web driver call method will never return. so, you can't move to the next line and not able to click ok or cancel button. one workaround is  inject some javascript method to override the showModalDialog method and change its behavior to open a normal window, but this way has some limitation, if your app requires some result return back from the javascript showModalDialog method, it does not work. below is the code, you can try:



JavascriptExecutor js = (JavascriptExecutor) ((WebDriverWrapper) context.getWebDriver()).getWebDriver();
String overrideShowModalDialogJs = "if(window.showModalDialog){";
overrideShowModalDialogJs += "window.showModalDialog = function( sURL, vArguments, sFeatures){";

overrideShowModalDialogJs += "window.open(sURL, 'modal', sFeatures);";
overrideShowModalDialogJs += "};}";

js.executeScript(overrideShowModalDialogJs);
make sure above code be executed before you click the button to trigger the modal dialog popup.

--david


From: seleniu...@googlegroups.com <seleniu...@googlegroups.com> on behalf of Anand Lambert <anand...@gmail.com>
Sent: Tuesday, May 16, 2017 1:49 PM
To: Selenium Users
Subject: [selenium-users] Not able to click "OK" on Popup !! ( Selenium/Python/Firefox )
 
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9995a3d9-4310-44bc-a077-817b10333b62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages