Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webdriver showModalDialog

We are using webdriver for our functional tests. But our application uses the showModalDialog JS function a lot to open a popup. When we try to test this functionality with webdriver it hangs from the moment the popup is opened.

We tried several things to test this:

  • Using the workaround explained here. But this seems to be a fix for selenium and not for webdriver. We tried it but it didn't work.
  • Searching for a good alternative, HtmlUnit opened the modal dialog and could interact with it, but it has it's drawbacks like no visual help to fix certain tests and it stopped execution when it detected a JS error in a JS library we have to use but have no control over.

How can we test this or work around this problem?

like image 535
johan gee Avatar asked Oct 21 '25 16:10

johan gee


2 Answers

From my experiences with various automation tools interaction with "webpage dialog" windows opened from IE using window.showModalDialog() or window.showModelessDialog() is not available.

Since the window is not a "true" window (look at the taskbar, it doesn't even show up) most tools can't "inspect" it and/or interact with it.

However if you do find a tool that will, please advise - there are many people looking for such a beast.

That all said, if you can possibly avoid using either of these 2 proprietary methods you'll have much more luck.

(and yes, for the picky ones, Firefox and Chrome have adopted these kind of dialogs but they don't work quite the same)

like image 114
scunliffe Avatar answered Oct 23 '25 06:10

scunliffe


None of the answers answer the question. If the driver hangs, then you can't call any methods on it. The question is NOT about finding the pop up, it is about how to stop the driver hanging. The only way I have found is to not use showModalDialog. This can be done by adding the folowing to your test code :

((JavascriptExecutor) driver).executeScript("window.showModalDialog = window.open;");

which calls window.open each time your JavaScript calls window.showModalDialog.

like image 23
Hugh Foster Avatar answered Oct 23 '25 05:10

Hugh Foster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!