Support for window.showModalDialog #284

Open
lukeis opened this Issue Mar 2, 2016 · 129 comments

Comments

@lukeis
Owner

lukeis commented Mar 2, 2016

Originally reported on Google Code with ID 284

What steps will reproduce the problem?
1. Visit http://developer.mozilla.org/samples/domref/showModalDialog.html
2. Use webdriver to click on the button to open up the modal dialog

What is the expected output? What do you see instead?
WebDriver blocks upon opening the modal dialog

What version of the product are you using? On what operating system?
Firefox/IE

Please provide any additional information below.
This is probably going to be possible after Issue #27 is resolved.

Reported by steveccrp on 2009-12-16 18:15:47

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
+1 for my vote!

As a workaround, this worked for me, though in my case I did not want a return value
as the modal dialog handled everything for the parent. Anyway thought I'd pass it on.

driver.executeScript("window.showModalDialog = window.openWindow;");

Reported by andrew.fawcett@coda.com on 2010-03-07 22:06:11

Owner

lukeis commented Mar 2, 2016

+1 for my vote!

As a workaround, this worked for me, though in my case I did not want a return value
as the modal dialog handled everything for the parent. Anyway thought I'd pass it on.

driver.executeScript("window.showModalDialog = window.openWindow;");

Reported by andrew.fawcett@coda.com on 2010-03-07 22:06:11

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Hi Andrew, I am trying to use your workaround to handle modal dialogs in my 
application. In my case the changes from pop-up have to be passed on the parent 
window. I tried driver.executeScript("return window.showModalDialog 
=window.openWindow;"); Didn't work. Do you have any other suggestions ? Thanks for

your help.

Reported by checkemail.wd on 2010-04-21 14:27:47

Owner

lukeis commented Mar 2, 2016

Hi Andrew, I am trying to use your workaround to handle modal dialogs in my 
application. In my case the changes from pop-up have to be passed on the parent 
window. I tried driver.executeScript("return window.showModalDialog 
=window.openWindow;"); Didn't work. Do you have any other suggestions ? Thanks for

your help.

Reported by checkemail.wd on 2010-04-21 14:27:47

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
After a year long of research on Modal Dialog to handle it through Selenium, I and 
my team at Sumtotal systems have formulated some workaround. It has been well tested

thoroughly as our application extensively uses modal dialogs. To make this work we

have modified IEBrowserBot.prototype.modifyWindowToRecordPopUpDialogs function 
defined in selenium-browserbot.js. The code snippet is attached. We expect some one

from selenium core team to include this in the Selenium Core so that every one of us

can take advantage of the same. For more details do visit 
http://seleniumdeal.blogspot.com/2010/04/working-with-modal-dialogs-and-selenium.html

Reported by vibhuti.amit on 2010-04-23 06:48:04


- _Attachment: [ModalDialog.txt](https://storage.googleapis.com/google-code-attachments/selenium/issue-284/comment-3/ModalDialog.txt)_
Owner

lukeis commented Mar 2, 2016

After a year long of research on Modal Dialog to handle it through Selenium, I and 
my team at Sumtotal systems have formulated some workaround. It has been well tested

thoroughly as our application extensively uses modal dialogs. To make this work we

have modified IEBrowserBot.prototype.modifyWindowToRecordPopUpDialogs function 
defined in selenium-browserbot.js. The code snippet is attached. We expect some one

from selenium core team to include this in the Selenium Core so that every one of us

can take advantage of the same. For more details do visit 
http://seleniumdeal.blogspot.com/2010/04/working-with-modal-dialogs-and-selenium.html

Reported by vibhuti.amit on 2010-04-23 06:48:04


- _Attachment: [ModalDialog.txt](https://storage.googleapis.com/google-code-attachments/selenium/issue-284/comment-3/ModalDialog.txt)_
@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
We also do have several show modal dialog box in our application but note that, some

show modal dialog boxes are not opening the perfect application window (Non modal 
window) with the code changes in browserbot.js, It's showing undefined in the window

(non modal window) and the actual functionality of the window is missing (e.g. if 
the modal pop up is for confirmation for delete something with the confirmation 
message and Yes no Button then it shows the message as undefined with yes no button,

also on clicking on yes button it's just closing the window without performing the

actual delete), It's not setting the return value and dialog.argument for the new 
opened non modal window so it's shows as undefined, is there any way to set the 
dialog argument to the non modal window 

Please let me know if you have any pointer for it.

you can also try out your code on following modal dialog box using selenium and your

updated code

http://msdn.microsoft.com/en-us/library/ms533723(VS.85).aspx

Click on "Show me" button to display the dialog


Please let me know if you have any pointer for it. 

Reported by ashish.joshi79 on 2010-05-15 02:56:25

Owner

lukeis commented Mar 2, 2016

We also do have several show modal dialog box in our application but note that, some

show modal dialog boxes are not opening the perfect application window (Non modal 
window) with the code changes in browserbot.js, It's showing undefined in the window

(non modal window) and the actual functionality of the window is missing (e.g. if 
the modal pop up is for confirmation for delete something with the confirmation 
message and Yes no Button then it shows the message as undefined with yes no button,

also on clicking on yes button it's just closing the window without performing the

actual delete), It's not setting the return value and dialog.argument for the new 
opened non modal window so it's shows as undefined, is there any way to set the 
dialog argument to the non modal window 

Please let me know if you have any pointer for it.

you can also try out your code on following modal dialog box using selenium and your

updated code

http://msdn.microsoft.com/en-us/library/ms533723(VS.85).aspx

Click on "Show me" button to display the dialog


Please let me know if you have any pointer for it. 

Reported by ashish.joshi79 on 2010-05-15 02:56:25

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Hi Amit,

I tried to use your workaround for modal dialogs in our application following the instructions
in http://seleniumdeal.blogspot.com/2010/04/working-with-modal-dialogs-and-selenium.html
- the popup dialog was opened but with "false" value and with javascript error: "Message:
'dialogArguments' is undefined"
Could you please advise ?

Thanks,
Yaffit

Reported by YaffitM on 2010-08-09 17:28:58

Owner

lukeis commented Mar 2, 2016

Hi Amit,

I tried to use your workaround for modal dialogs in our application following the instructions
in http://seleniumdeal.blogspot.com/2010/04/working-with-modal-dialogs-and-selenium.html
- the popup dialog was opened but with "false" value and with javascript error: "Message:
'dialogArguments' is undefined"
Could you please advise ?

Thanks,
Yaffit

Reported by YaffitM on 2010-08-09 17:28:58

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
We are experiencing same issue, is this some thing we expect to get fixed in near future
releases?? 

Reported by sridurgadevi on 2010-10-18 15:17:24

Owner

lukeis commented Mar 2, 2016

We are experiencing same issue, is this some thing we expect to get fixed in near future
releases?? 

Reported by sridurgadevi on 2010-10-18 15:17:24

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
I realy like to thank Amit for his solution - it worked for the application I am using.
I have followed his solution given in his blog dated 2009 "http://seleniumdeal.blogspot.com/2009/01/handling-modal-window-with-selenium.html"..I
too faced the same problem as said by 'YaffitM' but if we can arrange the code it will
work (but saying that I feel it might not be necessary). 

Reported by subhabratapal12 on 2010-10-26 07:35:57

Owner

lukeis commented Mar 2, 2016

I realy like to thank Amit for his solution - it worked for the application I am using.
I have followed his solution given in his blog dated 2009 "http://seleniumdeal.blogspot.com/2009/01/handling-modal-window-with-selenium.html"..I
too faced the same problem as said by 'YaffitM' but if we can arrange the code it will
work (but saying that I feel it might not be necessary). 

Reported by subhabratapal12 on 2010-10-26 07:35:57

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
A workaround for Firefox that we've been using successfully is to use Webdriver to focus
(sendKeys("");) on a particular element and then use Java's Robot class to simulate
the pressing of the spacebar to perform the action.  This allows the modal dialog to
open without blocking WebDriver which can then detect the window and switch to it appropriately.

The problem in IE that we're experiencing is that webdriver doesn't even recognize
the popup window as a new IE window.  It simply says that only 1 window exists whenever
a modal popup appears.  After looking (briefly) at the IEThreadElement.cpp file, I
noticed that the window class for a modal window within IE8 (I haven't tried with IE6/7
yet) doesn't contain the class that is used for modal popups ("Internet Explorer_TridentDlgFrame").
 I'm wondering if this is part of the reason while the show_modal_dialog functionality
doesn't work in IE.  

I can't verify if this would work since I don't have access to VS2008 or greater to
build the dll myself.

Hope this helps,
--Andy

Reported by swimminschrage on 2011-01-15 00:43:17

Owner

lukeis commented Mar 2, 2016

A workaround for Firefox that we've been using successfully is to use Webdriver to focus
(sendKeys("");) on a particular element and then use Java's Robot class to simulate
the pressing of the spacebar to perform the action.  This allows the modal dialog to
open without blocking WebDriver which can then detect the window and switch to it appropriately.

The problem in IE that we're experiencing is that webdriver doesn't even recognize
the popup window as a new IE window.  It simply says that only 1 window exists whenever
a modal popup appears.  After looking (briefly) at the IEThreadElement.cpp file, I
noticed that the window class for a modal window within IE8 (I haven't tried with IE6/7
yet) doesn't contain the class that is used for modal popups ("Internet Explorer_TridentDlgFrame").
 I'm wondering if this is part of the reason while the show_modal_dialog functionality
doesn't work in IE.  

I can't verify if this would work since I don't have access to VS2008 or greater to
build the dll myself.

Hope this helps,
--Andy

Reported by swimminschrage on 2011-01-15 00:43:17

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
As of 2.0b1, the IE driver C++ code has been completely rewritten. The method by which
windows are enumerated has completely changed. There is a TODO comment in the code
where handling for showModalDialog windows in IE should go. 

Reported by james.h.evans.jr on 2011-01-15 13:23:38

Owner

lukeis commented Mar 2, 2016

As of 2.0b1, the IE driver C++ code has been completely rewritten. The method by which
windows are enumerated has completely changed. There is a TODO comment in the code
where handling for showModalDialog windows in IE should go. 

Reported by james.h.evans.jr on 2011-01-15 13:23:38

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
A workaround that I used successful on my own project is by forking a new process to
do the action that blocks the normal flow of watir-webdriver or selenium (i.e. clicking
on the link that opens the modal dialog).

This way, the main process and the browser instance remains free to do window switching
and other actions.

This might seem a bit costly, as we ARE starting another process, but it doesn't depend
on yet another library (Java Robot, Sikuli, etc) nor does it require overriding any
code of the website you are testing (i.e. changing window.showModalDialog to window.open).

-Leo


Reported by leo.tumwattana on 2011-01-19 17:12:15

Owner

lukeis commented Mar 2, 2016

A workaround that I used successful on my own project is by forking a new process to
do the action that blocks the normal flow of watir-webdriver or selenium (i.e. clicking
on the link that opens the modal dialog).

This way, the main process and the browser instance remains free to do window switching
and other actions.

This might seem a bit costly, as we ARE starting another process, but it doesn't depend
on yet another library (Java Robot, Sikuli, etc) nor does it require overriding any
code of the website you are testing (i.e. changing window.showModalDialog to window.open).

-Leo


Reported by leo.tumwattana on 2011-01-19 17:12:15

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner

Reported by dharani@google.com on 2011-01-21 00:46:32

  • Labels added: Type-Enhancement, Browser-Firefox
  • Labels removed: Type-Defect
Owner

lukeis commented Mar 2, 2016

Reported by dharani@google.com on 2011-01-21 00:46:32

  • Labels added: Type-Enhancement, Browser-Firefox
  • Labels removed: Type-Defect
@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Hi, Leo, Can you describe your workaround in detail? How did you forking a new process
with selenium? Thanks.

Andy, which version of selenium you are using? 2.0?

I am desparated for a solution to handle modal dialog issue on firefox or IE 6....

Reported by Zaixia.Zhang on 2011-01-21 10:28:10

Owner

lukeis commented Mar 2, 2016

Hi, Leo, Can you describe your workaround in detail? How did you forking a new process
with selenium? Thanks.

Andy, which version of selenium you are using? 2.0?

I am desparated for a solution to handle modal dialog issue on firefox or IE 6....

Reported by Zaixia.Zhang on 2011-01-21 10:28:10

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
I was using 2.0b1 and was looking at the trunk code here on the site when I made my
previous post.  I'm assuming the public browsable source located here on the code.google
site IS the rewritten IE driver. 

Not sure why this is being classified as a Firefox only "enhancement"?

Did I miss something?  Are others not seeing the same behavior when using 2.0b1 with
IE?

Reported by swimminschrage on 2011-01-21 18:02:55

Owner

lukeis commented Mar 2, 2016

I was using 2.0b1 and was looking at the trunk code here on the site when I made my
previous post.  I'm assuming the public browsable source located here on the code.google
site IS the rewritten IE driver. 

Not sure why this is being classified as a Firefox only "enhancement"?

Did I miss something?  Are others not seeing the same behavior when using 2.0b1 with
IE?

Reported by swimminschrage on 2011-01-21 18:02:55

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Hi Zaixiz,

First off, let me clarify that I code in Ruby and I use Watir-Webdriver which in turn
uses Selenium-Webdriver to automate browsers.  So, you'll have to translate any details
I give to their equivalent in pure Selenium and the language of your preference.

The problem with opening a modal popup is that the current process gets blocked waiting
on the parent window.  However, the browser instance from Selenium itself is not blocked.
 I've found that you can still work with the browser instance if somehow your process
can continue to new lines of code.

So, my workaround is to start a new process, which activates the modal popup.  The
new process becomes the escape goat that gets blocked.  This leaves my original process
free to continue onto code that does the window switching and closing of the modal
popup.

In Ruby, you can clone a current process with the "fork" method.  From my limited understanding,
Java does not do "fork" very well (please correct me if I am wrong and this is assuming
you are using Java).  However, you might try starting a new thread in Java instead
of a new process.

Anyway, this is how the Ruby code would look like:

browser = Watir::Browser.new(:firefox)

pid = fork {
  browser.button(:id, "some-value").click  //clicking on the button that activates
the modal popup
  // This process gets blocked until the parent window gets back its control from the
modal popup
}

// The current process continues onto the code below
// You might have to tell Selenium to wait for the modal popup to appear somehow
// Then proceed to switch to the modal popup
browser.driver.switch_to.window(browser.driver.window_handles.last)  //assuming the
last window is the popup
browser.button(:id, "some-value").click //Do something in the popup or click on the
close button or whatever else you want to do
browser.driver.switch_to.window(browser.driver.window_handles.first) //assuming the
first window is the original parent window you want to continue you work on.

Obviously, you'll have to fill in the blank and possible be more rigorous in selecting
the window to use...but that's basically how you would do this.  As mentioned earlier,
you might want to try starting a new Thread as oppose to a new process if you are using
Java.  I had to use fork to start a new process in Ruby, because threads are not really
full-blown threads in Ruby.

Hope this helps,

Leo

Reported by leo.tumwattana on 2011-01-22 17:40:19

Owner

lukeis commented Mar 2, 2016

Hi Zaixiz,

First off, let me clarify that I code in Ruby and I use Watir-Webdriver which in turn
uses Selenium-Webdriver to automate browsers.  So, you'll have to translate any details
I give to their equivalent in pure Selenium and the language of your preference.

The problem with opening a modal popup is that the current process gets blocked waiting
on the parent window.  However, the browser instance from Selenium itself is not blocked.
 I've found that you can still work with the browser instance if somehow your process
can continue to new lines of code.

So, my workaround is to start a new process, which activates the modal popup.  The
new process becomes the escape goat that gets blocked.  This leaves my original process
free to continue onto code that does the window switching and closing of the modal
popup.

In Ruby, you can clone a current process with the "fork" method.  From my limited understanding,
Java does not do "fork" very well (please correct me if I am wrong and this is assuming
you are using Java).  However, you might try starting a new thread in Java instead
of a new process.

Anyway, this is how the Ruby code would look like:

browser = Watir::Browser.new(:firefox)

pid = fork {
  browser.button(:id, "some-value").click  //clicking on the button that activates
the modal popup
  // This process gets blocked until the parent window gets back its control from the
modal popup
}

// The current process continues onto the code below
// You might have to tell Selenium to wait for the modal popup to appear somehow
// Then proceed to switch to the modal popup
browser.driver.switch_to.window(browser.driver.window_handles.last)  //assuming the
last window is the popup
browser.button(:id, "some-value").click //Do something in the popup or click on the
close button or whatever else you want to do
browser.driver.switch_to.window(browser.driver.window_handles.first) //assuming the
first window is the original parent window you want to continue you work on.

Obviously, you'll have to fill in the blank and possible be more rigorous in selecting
the window to use...but that's basically how you would do this.  As mentioned earlier,
you might want to try starting a new Thread as oppose to a new process if you are using
Java.  I had to use fork to start a new process in Ruby, because threads are not really
full-blown threads in Ruby.

Hope this helps,

Leo

Reported by leo.tumwattana on 2011-01-22 17:40:19

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Regarding IEThreadElement.cpp: Yes, the code posted here contains the rewritten IE driver;
however, the old replaced code is still in the repository too. We (read: I) haven't
deleted it yet. The old code is in the InternetExplorerDriver directory under the cpp
folder. The new code replacing it is under the IEDriver directory. IEThreadElement.cpp
is in the former directory, and thus should be disregarded in looking at the source
code to understand the IE driver's behaviour. Under the latter directory, there is
a TODO comment in BrowserManager.cpp (at line 244, as of this writing) that reads:

  // TODO: Enumerate windows looking for browser windows
  // created by showModalDialog().

Reported by james.h.evans.jr on 2011-01-22 18:35:12

Owner

lukeis commented Mar 2, 2016

Regarding IEThreadElement.cpp: Yes, the code posted here contains the rewritten IE driver;
however, the old replaced code is still in the repository too. We (read: I) haven't
deleted it yet. The old code is in the InternetExplorerDriver directory under the cpp
folder. The new code replacing it is under the IEDriver directory. IEThreadElement.cpp
is in the former directory, and thus should be disregarded in looking at the source
code to understand the IE driver's behaviour. Under the latter directory, there is
a TODO comment in BrowserManager.cpp (at line 244, as of this writing) that reads:

  // TODO: Enumerate windows looking for browser windows
  // created by showModalDialog().

Reported by james.h.evans.jr on 2011-01-22 18:35:12

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner

Any one out there able to implement the solution suggested by Leo with IE webdriver
2.0b1 version using java bindings??

When I was trying to do that HttpClient was throwing an error with SingleConnection
manager, which actually makes sense as client didnt get control back from the previous
request and when we span a child thread and try to send one more request to the window
it throws an error about connection.
Am I missing some thing??


Reported by sridurgadevi on 2011-01-28 16:35:48

Owner

lukeis commented Mar 2, 2016


Any one out there able to implement the solution suggested by Leo with IE webdriver
2.0b1 version using java bindings??

When I was trying to do that HttpClient was throwing an error with SingleConnection
manager, which actually makes sense as client didnt get control back from the previous
request and when we span a child thread and try to send one more request to the window
it throws an error about connection.
Am I missing some thing??


Reported by sridurgadevi on 2011-01-28 16:35:48

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Did anybody try to use Watin+Selenium?
in my case, Watin does not open modal dialogs too.

In case when I am using patched Selenium (described some posts higher), and executing
this code:

var dialog = IE.AttachToIE(Find.ByUrl(url));
            dialog.Element(Find.ByText("Add")).Click();
            HtmlDialog regarding = dialog.HtmlDialog(Find.ByTitle("Look Up Records"),
10);

watin cannot find displayed modal dialog.

Reported by d2.lebedev on 2011-02-01 10:44:23

Owner

lukeis commented Mar 2, 2016

Did anybody try to use Watin+Selenium?
in my case, Watin does not open modal dialogs too.

In case when I am using patched Selenium (described some posts higher), and executing
this code:

var dialog = IE.AttachToIE(Find.ByUrl(url));
            dialog.Element(Find.ByText("Add")).Click();
            HtmlDialog regarding = dialog.HtmlDialog(Find.ByTitle("Look Up Records"),
10);

watin cannot find displayed modal dialog.

Reported by d2.lebedev on 2011-02-01 10:44:23

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Just for those of you wanting to help out, BrowserManager.cpp referenced above has been
renamed Session.cpp. The comment for modal dialog support is still there at line 282.
Trying hard...but cpp's not my cup of tea really :'(

Reported by paul.pirat on 2011-04-05 07:12:42

Owner

lukeis commented Mar 2, 2016

Just for those of you wanting to help out, BrowserManager.cpp referenced above has been
renamed Session.cpp. The comment for modal dialog support is still there at line 282.
Trying hard...but cpp's not my cup of tea really :'(

Reported by paul.pirat on 2011-04-05 07:12:42

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
James Evans has posted a changelist that aims at solving this issue for the IE driver.
Look for r11989 for the recompiled libraries! Thanks James!

Reported by paul.pirat on 2011-04-15 20:28:06

Owner

lukeis commented Mar 2, 2016

James Evans has posted a changelist that aims at solving this issue for the IE driver.
Look for r11989 for the recompiled libraries! Thanks James!

Reported by paul.pirat on 2011-04-15 20:28:06

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
I tried to use the new driver dll that James posted, but now IE won't start in WebDriver,
any thoughts?

Reported by robert.evans25 on 2011-05-31 20:23:00

Owner

lukeis commented Mar 2, 2016

I tried to use the new driver dll that James posted, but now IE won't start in WebDriver,
any thoughts?

Reported by robert.evans25 on 2011-05-31 20:23:00

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
What do you mean by "IE doesn't start"? Do you receive any error messages? What does
your test code look like?

Reported by james.h.evans.jr on 2011-06-01 11:52:36

Owner

lukeis commented Mar 2, 2016

What do you mean by "IE doesn't start"? Do you receive any error messages? What does
your test code look like?

Reported by james.h.evans.jr on 2011-06-01 11:52:36

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
It would open.  I was using the dll that I pulled directly from a subversion checkout,
i tried the one attached to this ticket and all works well.  Not quite sure why the
one from the checkout wouldn't open IE, any idea?

Reported by robert.evans25 on 2011-06-01 22:42:56

Owner

lukeis commented Mar 2, 2016

It would open.  I was using the dll that I pulled directly from a subversion checkout,
i tried the one attached to this ticket and all works well.  Not quite sure why the
one from the checkout wouldn't open IE, any idea?

Reported by robert.evans25 on 2011-06-01 22:42:56

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Has anyone come across with Internet Explorer that their modal windows (created via
show_modal_dialog) are not recognized with Selenium 2.0.0?  See my earlier comment
#8 for the specific problem I'm having with IE.

WebDriver doesn't seem to recognize the modals as windows at all.  The call to getWindowHandles()
always returns 1 (for the window that generated the modal).

Reported by swimminschrage on 2011-07-15 18:13:58

Owner

lukeis commented Mar 2, 2016

Has anyone come across with Internet Explorer that their modal windows (created via
show_modal_dialog) are not recognized with Selenium 2.0.0?  See my earlier comment
#8 for the specific problem I'm having with IE.

WebDriver doesn't seem to recognize the modals as windows at all.  The call to getWindowHandles()
always returns 1 (for the window that generated the modal).

Reported by swimminschrage on 2011-07-15 18:13:58

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Comment 9 indicates that the IE driver has been completely rewritten since you posted
your comment (IEThreadElement.cpp is no longer even in the project!). Are you still
experiencing problems with the latest release? There *is* a known race condition in
the handling of showModalDialog() popup windows in IE, but it shouldn't be all that
often that you would see that. A pointer to a public page where the problem can be
reproduced would help immensely.

Reported by james.h.evans.jr on 2011-07-15 20:31:51

Owner

lukeis commented Mar 2, 2016

Comment 9 indicates that the IE driver has been completely rewritten since you posted
your comment (IEThreadElement.cpp is no longer even in the project!). Are you still
experiencing problems with the latest release? There *is* a known race condition in
the handling of showModalDialog() popup windows in IE, but it shouldn't be all that
often that you would see that. A pointer to a public page where the problem can be
reproduced would help immensely.

Reported by james.h.evans.jr on 2011-07-15 20:31:51

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Thanks James.

You're right.  It seems to be working for me now.  Turns out that the problem was that
the action that generates the modal (losing focus or clicking a button on the page)
needs to be performed by WebDriver in order for WebDriver to see the new window.  My
framework used Keyboard commands to trigger the modal (due to a WebDriver FF bug) and
so when run from IE I wasn't able to get access to the modal at runtime.

I am however running into a new issue with iframes on those modal windows.  I can't
seem to switchTo() my iFrame the same way I do for the non-modal windows.  The switchTo()
statement doesn't throw an exception, but the following find method can't find the
element within the iframe because the WebDriver context hasn't been successfully changed
to the iframe.  Any thoughts?  Or should I create a new bug for it.

Reported by swimminschrage on 2011-07-19 19:06:18

Owner

lukeis commented Mar 2, 2016

Thanks James.

You're right.  It seems to be working for me now.  Turns out that the problem was that
the action that generates the modal (losing focus or clicking a button on the page)
needs to be performed by WebDriver in order for WebDriver to see the new window.  My
framework used Keyboard commands to trigger the modal (due to a WebDriver FF bug) and
so when run from IE I wasn't able to get access to the modal at runtime.

I am however running into a new issue with iframes on those modal windows.  I can't
seem to switchTo() my iFrame the same way I do for the non-modal windows.  The switchTo()
statement doesn't throw an exception, but the following find method can't find the
element within the iframe because the WebDriver context hasn't been successfully changed
to the iframe.  Any thoughts?  Or should I create a new bug for it.

Reported by swimminschrage on 2011-07-19 19:06:18

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
I have a button that opens a new window with window.showModalDialog().  When I click
it with InternetExplorerDriver (with IE8 and selenium 2.1.0), it doesn't always show
up in WindowHandles.  Sometimes it does, sometimes it doesn't -- I haven't found any
consistency here.  Might this be due to the race condition James mentioned in comment
26?

Note that WindowHandles are always updated when window.open() is used.

Thanks!

Reported by tchyup on 2011-07-26 15:19:25

Owner

lukeis commented Mar 2, 2016

I have a button that opens a new window with window.showModalDialog().  When I click
it with InternetExplorerDriver (with IE8 and selenium 2.1.0), it doesn't always show
up in WindowHandles.  Sometimes it does, sometimes it doesn't -- I haven't found any
consistency here.  Might this be due to the race condition James mentioned in comment
26?

Note that WindowHandles are always updated when window.open() is used.

Thanks!

Reported by tchyup on 2011-07-26 15:19:25

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
NOTE for comment 29:

I'm not sure if it makes a difference, but I'm using window.showModalDialog() in a
particular fashion to display a custom modal dialog.  The JavaScript is as follows:

var returnObjectModifiedByModalDialog = new Object();

var returnAction = window.showModalDialog("url in here" + someStringAppendedToUrl,returnObjectModifiedByModalDialog,"window
attributes in here");

Reported by tchyup on 2011-07-28 16:15:52

Owner

lukeis commented Mar 2, 2016

NOTE for comment 29:

I'm not sure if it makes a difference, but I'm using window.showModalDialog() in a
particular fashion to display a custom modal dialog.  The JavaScript is as follows:

var returnObjectModifiedByModalDialog = new Object();

var returnAction = window.showModalDialog("url in here" + someStringAppendedToUrl,returnObjectModifiedByModalDialog,"window
attributes in here");

Reported by tchyup on 2011-07-28 16:15:52

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Issue 1839 has been merged into this issue.

Reported by david.burns@theautomatedtester.co.uk on 2011-08-31 17:16:43

Owner

lukeis commented Mar 2, 2016

Issue 1839 has been merged into this issue.

Reported by david.burns@theautomatedtester.co.uk on 2011-08-31 17:16:43

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Hi,

I too have a similar issue with model popups in our project.I am using selenium2.0.
I have a button in my application, clicking on this button opens a model window. when
i execute the selenium script in firefox, the script gets hanged on button click even
though the model window is opening i am unable to select it using its title by "selenium.selectwindow()"
command.

I have made the necessary changes in selenium server.jar as mention in the Amit's blog
but i am out of ideas to handle the issue.

When i run the script in debug mode the cursor get stuck at the button click and it
is not coming to the next step where i have specified command to select the window.

Code looks like this
------------------------
 selenium.click("//input[@value='Associate']");-->getting stuck here

 selenium.focus("title=XYZ: Associate Sites to Master Document");
 selenium.selectWindow("title=XYZ: Associate Sites to Master Document");

from the selenium IDE script the window name is

selenium.selectWindow("name=modalWindow1234");---> the model window name changes dynamically
. for example next time when i click for modelwindow it could be "name=modalWindow5432".
So i have tried to use as selenium.selectWindow("name=modalWindow*").But since the
script is getting stuck at the previous step itself i am unable to check if it works.

FYI
-----

When i click on Associate button which shows the modelwindow using selenium IDE i could
see two command getting executed.
step-1
selenium.open("/ master_list.do?sgjy=u6aeu1po2qamanj6q0b5f0ul6e9g7mvy");
step-2
selenium.click("//input[@value='Associate']"); 


but the model pop window is not "master_site_list" and "master_list" is a parent window.


Could some one help me how to handle this issue.

And also help me how to use the modified selenium-server.jar in my script.

Thanks,
Rajesh

Reported by ratakonda.rajesh on 2011-09-23 02:29:34

Owner

lukeis commented Mar 2, 2016

Hi,

I too have a similar issue with model popups in our project.I am using selenium2.0.
I have a button in my application, clicking on this button opens a model window. when
i execute the selenium script in firefox, the script gets hanged on button click even
though the model window is opening i am unable to select it using its title by "selenium.selectwindow()"
command.

I have made the necessary changes in selenium server.jar as mention in the Amit's blog
but i am out of ideas to handle the issue.

When i run the script in debug mode the cursor get stuck at the button click and it
is not coming to the next step where i have specified command to select the window.

Code looks like this
------------------------
 selenium.click("//input[@value='Associate']");-->getting stuck here

 selenium.focus("title=XYZ: Associate Sites to Master Document");
 selenium.selectWindow("title=XYZ: Associate Sites to Master Document");

from the selenium IDE script the window name is

selenium.selectWindow("name=modalWindow1234");---> the model window name changes dynamically
. for example next time when i click for modelwindow it could be "name=modalWindow5432".
So i have tried to use as selenium.selectWindow("name=modalWindow*").But since the
script is getting stuck at the previous step itself i am unable to check if it works.

FYI
-----

When i click on Associate button which shows the modelwindow using selenium IDE i could
see two command getting executed.
step-1
selenium.open("/ master_list.do?sgjy=u6aeu1po2qamanj6q0b5f0ul6e9g7mvy");
step-2
selenium.click("//input[@value='Associate']"); 


but the model pop window is not "master_site_list" and "master_list" is a parent window.


Could some one help me how to handle this issue.

And also help me how to use the modified selenium-server.jar in my script.

Thanks,
Rajesh

Reported by ratakonda.rajesh on 2011-09-23 02:29:34

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
HI All, Can any one have a solution for my post on Sep22.Its an priority requirement
in implementing selenium on our project as i am stuck in modalwindow.

Regards,
Rajesh.

Reported by ratakonda.rajesh on 2011-09-28 14:09:58

Owner

lukeis commented Mar 2, 2016

HI All, Can any one have a solution for my post on Sep22.Its an priority requirement
in implementing selenium on our project as i am stuck in modalwindow.

Regards,
Rajesh.

Reported by ratakonda.rajesh on 2011-09-28 14:09:58

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Rajesh, I'm not totally up to date with this thread. But I also had the problem when
clicking the modal dialog. A fix for me is to use Webdriver to focus (sendKeys("");)
on a particular element and then use Java's Robot class to simulate the pressing of
the spacebar to perform the action.  This allows the modal dialog to open without blocking
WebDriver which can then detect the window and switch to it appropriately.(this is
described in comment #8). 

The workaround is not bulletproof because it simulates pressing the spacebar on the
element that has the focus. But if you are just browsing the internet while running
the test(s) and the java robot class presses spacebar when the focus is on something
else, your test will fail. 

Reported by nick.vanroey on 2011-09-28 14:22:13

Owner

lukeis commented Mar 2, 2016

Rajesh, I'm not totally up to date with this thread. But I also had the problem when
clicking the modal dialog. A fix for me is to use Webdriver to focus (sendKeys("");)
on a particular element and then use Java's Robot class to simulate the pressing of
the spacebar to perform the action.  This allows the modal dialog to open without blocking
WebDriver which can then detect the window and switch to it appropriately.(this is
described in comment #8). 

The workaround is not bulletproof because it simulates pressing the spacebar on the
element that has the focus. But if you are just browsing the internet while running
the test(s) and the java robot class presses spacebar when the focus is on something
else, your test will fail. 

Reported by nick.vanroey on 2011-09-28 14:22:13

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Hi All,
I am trying to test automate of a  webpage which opens a modal dialog with iframe.
I use webdriver (selenium-server-standalone-2.7.0.jar). When i try to find an element
using xpath on the modal dialog, but i am not able to find it. I even tried to get
a window handle on the modal dialog box but was unsuccessful. This issue is very critical
to my project. Is this issue planned to be solved for next release of webdriver? 

-Dinesh

Reported by dinesh12b on 2011-10-04 17:51:26

Owner

lukeis commented Mar 2, 2016

Hi All,
I am trying to test automate of a  webpage which opens a modal dialog with iframe.
I use webdriver (selenium-server-standalone-2.7.0.jar). When i try to find an element
using xpath on the modal dialog, but i am not able to find it. I even tried to get
a window handle on the modal dialog box but was unsuccessful. This issue is very critical
to my project. Is this issue planned to be solved for next release of webdriver? 

-Dinesh

Reported by dinesh12b on 2011-10-04 17:51:26

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Issue 3615 has been merged into this issue.

Reported by barancev on 2012-05-19 20:48:49

Owner

lukeis commented Mar 2, 2016

Issue 3615 has been merged into this issue.

Reported by barancev on 2012-05-19 20:48:49

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
In my modal dialog popup window there are some mandatory fields when i 
clicked submit button to verify mandatory fields then java script 
alerts take place but i m not able to verify such alerts using the 
selenium.isalertpresent() or driver.switchto().alert() and console print noalertpresent
exception.

Reported by hmanoj36 on 2012-05-25 14:57:58

Owner

lukeis commented Mar 2, 2016

In my modal dialog popup window there are some mandatory fields when i 
clicked submit button to verify mandatory fields then java script 
alerts take place but i m not able to verify such alerts using the 
selenium.isalertpresent() or driver.switchto().alert() and console print noalertpresent
exception.

Reported by hmanoj36 on 2012-05-25 14:57:58

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Issue 3989 has been merged into this issue.

Reported by barancev on 2012-05-31 03:13:09

Owner

lukeis commented Mar 2, 2016

Issue 3989 has been merged into this issue.

Reported by barancev on 2012-05-31 03:13:09

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner

Reported by barancev on 2012-05-31 03:15:35

  • Labels added: Browser-Chrome, Browser-Firefox
Owner

lukeis commented Mar 2, 2016

Reported by barancev on 2012-05-31 03:15:35

  • Labels added: Browser-Chrome, Browser-Firefox
@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
see comment 107......i m facing same problem in 2.22 version as well.

Reported by hmanoj36 on 2012-05-31 15:19:14

Owner

lukeis commented Mar 2, 2016

see comment 107......i m facing same problem in 2.22 version as well.

Reported by hmanoj36 on 2012-05-31 15:19:14

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
First we need to override the modal dialog to make it a modeless dialog.
Second we need to alter the function that calls the modal dialog to be a function that
the child window calls...instead of a function that pauses and waits for a return value.
Third we need to override the child window return function to call our new parent window
function instead of passing back a single variable.

Below is how it would work....I know it's kind of messy but it's round 1.

-------------------------------------------------

def open_Modal(wd, cmd):
    wd.execute_script("window.top.showModalDialog = function(sURL, vArguments, sFeatures)"
            + "{"
            + "window.top.showModelessDialog(sURL, window, sFeatures);"
            #+ "window.open(sURL, 'window', sFeatures);"
            + "}")
    #this function is always random we need to grab all but the modal dialog statement!!!!!
    wd.execute_script("createFunction = function()"
        + "{"
        + "var str = changeWorkState.toString();"
        + "var x = str.indexOf(\")\") + 1;"
        + "var str = str.substring(x, str.length);"
        + "var str = str.replace(\"var results = window.top.showModalDialog(\\\"DW_SecondaryState.jsp\\\",
\""
        + "+ \"[window, document], 'dialogWidth=500px; dialogHeight=300px; status:no;
help:no; scroll:no');\", \"\");"
        + "return str;" 
        + "}")
    str = wd.execute_script("return createFunction();")
    wd.execute_script("workStateUpdate = function(results)" + str)
    #wd.execute_script("window.top.showModalDialog = window.top.showModelessDialog;")
    #wd.execute_script("window.top.showModalDialog = launchManagedDialog;")
    #wd.execute_script("window.top.showModalDialog = window.showModelessDialog;")

    rc = "True"
    try:
        print "THIS IS THE CODE: " + cmd
        eval(cmd)
        #switch window handle
        #s = self.driver.window_handles
        #for item in s:
        #    print "HANDLE " + str(item)
        #    if item != self.driver.current_window_handle:
        #        print "USING HANDLE: " + item
        #        self.driver.switch_to_window(item)
        #        break
        #thread.start_new_thread(fork, (wd, cmd, ))
    except NoSuchElementException, e:
        rc = "False"
    return rc

def injectChild(wd):
    msg = switchHandle(wd)
    if msg == "window not found":
        return msg
    wd.execute_script("selectState = function(stCd, slot)"
        + "{"
        + "var stateInfo = new Array(2);"
        + "stateInfo[0] = stCd;"
        + "stateInfo[1] = slot;"
        + "var sData = dialogArguments;"
        + "sData.workStateUpdate(stateInfo);"
        + "window.close();"
        + "}")

def switchHandle(wd):
    print "length: " + str(len(wd.window_handles))
    if len(wd.window_handles) <= 1:
        return "window not found"

    handles = wd.window_handles
    for handle in handles:
        print "HANDLE " + str(handle)
        if handle != wd.current_window_handle:
            print "USING HANDLE: " + handle
            wd.switch_to_window(handle)
            return "found"

Reported by murph1329 on 2012-06-19 12:43:30

Owner

lukeis commented Mar 2, 2016

First we need to override the modal dialog to make it a modeless dialog.
Second we need to alter the function that calls the modal dialog to be a function that
the child window calls...instead of a function that pauses and waits for a return value.
Third we need to override the child window return function to call our new parent window
function instead of passing back a single variable.

Below is how it would work....I know it's kind of messy but it's round 1.

-------------------------------------------------

def open_Modal(wd, cmd):
    wd.execute_script("window.top.showModalDialog = function(sURL, vArguments, sFeatures)"
            + "{"
            + "window.top.showModelessDialog(sURL, window, sFeatures);"
            #+ "window.open(sURL, 'window', sFeatures);"
            + "}")
    #this function is always random we need to grab all but the modal dialog statement!!!!!
    wd.execute_script("createFunction = function()"
        + "{"
        + "var str = changeWorkState.toString();"
        + "var x = str.indexOf(\")\") + 1;"
        + "var str = str.substring(x, str.length);"
        + "var str = str.replace(\"var results = window.top.showModalDialog(\\\"DW_SecondaryState.jsp\\\",
\""
        + "+ \"[window, document], 'dialogWidth=500px; dialogHeight=300px; status:no;
help:no; scroll:no');\", \"\");"
        + "return str;" 
        + "}")
    str = wd.execute_script("return createFunction();")
    wd.execute_script("workStateUpdate = function(results)" + str)
    #wd.execute_script("window.top.showModalDialog = window.top.showModelessDialog;")
    #wd.execute_script("window.top.showModalDialog = launchManagedDialog;")
    #wd.execute_script("window.top.showModalDialog = window.showModelessDialog;")

    rc = "True"
    try:
        print "THIS IS THE CODE: " + cmd
        eval(cmd)
        #switch window handle
        #s = self.driver.window_handles
        #for item in s:
        #    print "HANDLE " + str(item)
        #    if item != self.driver.current_window_handle:
        #        print "USING HANDLE: " + item
        #        self.driver.switch_to_window(item)
        #        break
        #thread.start_new_thread(fork, (wd, cmd, ))
    except NoSuchElementException, e:
        rc = "False"
    return rc

def injectChild(wd):
    msg = switchHandle(wd)
    if msg == "window not found":
        return msg
    wd.execute_script("selectState = function(stCd, slot)"
        + "{"
        + "var stateInfo = new Array(2);"
        + "stateInfo[0] = stCd;"
        + "stateInfo[1] = slot;"
        + "var sData = dialogArguments;"
        + "sData.workStateUpdate(stateInfo);"
        + "window.close();"
        + "}")

def switchHandle(wd):
    print "length: " + str(len(wd.window_handles))
    if len(wd.window_handles) <= 1:
        return "window not found"

    handles = wd.window_handles
    for handle in handles:
        print "HANDLE " + str(handle)
        if handle != wd.current_window_handle:
            print "USING HANDLE: " + handle
            wd.switch_to_window(handle)
            return "found"

Reported by murph1329 on 2012-06-19 12:43:30

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
of course a better option would be to find your developers and tell them to use modeless
dialogs instead of modal dialogs.....then again it's hard enough for those guys to
use name and id attributes

Reported by murph1329 on 2012-06-19 12:58:15

Owner

lukeis commented Mar 2, 2016

of course a better option would be to find your developers and tell them to use modeless
dialogs instead of modal dialogs.....then again it's hard enough for those guys to
use name and id attributes

Reported by murph1329 on 2012-06-19 12:58:15

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
I am still getting this error..Is this issue fixed in 2.24.1 version for firefox?

System.InvalidOperationException : Modal dialog present
Build info: version: '2.24.1', 
Driver info: driver.version: FirefoxDriver

Please suggest any workaround ..

Reported by pankajjethlia on 2012-08-09 19:26:40

Owner

lukeis commented Mar 2, 2016

I am still getting this error..Is this issue fixed in 2.24.1 version for firefox?

System.InvalidOperationException : Modal dialog present
Build info: version: '2.24.1', 
Driver info: driver.version: FirefoxDriver

Please suggest any workaround ..

Reported by pankajjethlia on 2012-08-09 19:26:40

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
I'm still getting this error. Using FF 10 and Selenium 2.25
Any plans to fix this issue?
Regards Geogre

Reported by geokh77@hotmail.com on 2012-08-27 08:18:59

Owner

lukeis commented Mar 2, 2016

I'm still getting this error. Using FF 10 and Selenium 2.25
Any plans to fix this issue?
Regards Geogre

Reported by geokh77@hotmail.com on 2012-08-27 08:18:59

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
I've been using this workaround for a while now. Not sure if it would implementable
by others.

When you click on a button or link that opens a modal dialog, the dialog opens uup
and WebDriver gets blocked waiting for a response. 

Implement this click in a child thread while the parent thread moves on.
In the parent thread, if you can find a way to get hold of this new window (using an
alternative lightweight framework), then get that framework to click on this window
using the mouse. 

Once you click, the child thread will proceed and you should have WebDriver back in
control and working as expected. This has worked for us.

Reported by ravindrarupadhya on 2012-08-31 09:46:37

Owner

lukeis commented Mar 2, 2016

I've been using this workaround for a while now. Not sure if it would implementable
by others.

When you click on a button or link that opens a modal dialog, the dialog opens uup
and WebDriver gets blocked waiting for a response. 

Implement this click in a child thread while the parent thread moves on.
In the parent thread, if you can find a way to get hold of this new window (using an
alternative lightweight framework), then get that framework to click on this window
using the mouse. 

Once you click, the child thread will proceed and you should have WebDriver back in
control and working as expected. This has worked for us.

Reported by ravindrarupadhya on 2012-08-31 09:46:37

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Issue 4582 has been merged into this issue.

Reported by barancev on 2012-09-27 19:02:07

Owner

lukeis commented Mar 2, 2016

Issue 4582 has been merged into this issue.

Reported by barancev on 2012-09-27 19:02:07

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
using WebDriver 2.2
Ravindra, The same thing worked for us too. Below is the code that worked:

driver.get("https://your_test_application.com/");
Thread thread1 = new Thread(new Runnable() {
    @Override
   public void run() {
    System.out.println("thread running..");
    WebElement webElement = driver.findElement(By.xpath("//*[@src='/images/magnify.gif']"));
    webElement.click();
  }
thread1.start();
Thread.sleep(4000); //wait for the popup to open
thread1.stop();
windowHandles = driver.getWindowHandles();
it = windowHandles.iterator();
String windowHandle = "";
while(it.hasNext()){
  windowHandle = it.next();
}

//switch focus to the popup and work on the popup
driver.switchTo().window(windowHandle);
driver.findElement(By.name("searchName")).sendKeys("ABCD");



Reported by kalyanparupalli on 2012-10-29 07:14:19

Owner

lukeis commented Mar 2, 2016

using WebDriver 2.2
Ravindra, The same thing worked for us too. Below is the code that worked:

driver.get("https://your_test_application.com/");
Thread thread1 = new Thread(new Runnable() {
    @Override
   public void run() {
    System.out.println("thread running..");
    WebElement webElement = driver.findElement(By.xpath("//*[@src='/images/magnify.gif']"));
    webElement.click();
  }
thread1.start();
Thread.sleep(4000); //wait for the popup to open
thread1.stop();
windowHandles = driver.getWindowHandles();
it = windowHandles.iterator();
String windowHandle = "";
while(it.hasNext()){
  windowHandle = it.next();
}

//switch focus to the popup and work on the popup
driver.switchTo().window(windowHandle);
driver.findElement(By.name("searchName")).sendKeys("ABCD");



Reported by kalyanparupalli on 2012-10-29 07:14:19

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
This does not work for me on Windows 7 > Chrome 23 > Selenium 2.25.1 using dotNet binaries.

Anyone upgraded to this combination yet and got a workaround?

Reported by ravindrarupadhya on 2012-11-01 13:16:36

Owner

lukeis commented Mar 2, 2016

This does not work for me on Windows 7 > Chrome 23 > Selenium 2.25.1 using dotNet binaries.

Anyone upgraded to this combination yet and got a workaround?

Reported by ravindrarupadhya on 2012-11-01 13:16:36

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Hi,

the trick with the thread didn't work for me either.
I'm using Selenium-webdriver version 2.26, with IE9 and FF-16.02, and Windows7.
Selenium-webdriver doesn't recognize any element on a modal window on both browsers.
In additions after the modal is opened "driver.getWindowHandles()" returns only 1 hanlde
which belongs to the main(parent) window. I'm considering to return to Selenium1 because
the application I'm automating relies on many modal popup windows.

This is quite disappointment to find out that Selenium2 can't handle modal windows!

Reported by Ido.Levi1974 on 2012-11-08 21:23:04

Owner

lukeis commented Mar 2, 2016

Hi,

the trick with the thread didn't work for me either.
I'm using Selenium-webdriver version 2.26, with IE9 and FF-16.02, and Windows7.
Selenium-webdriver doesn't recognize any element on a modal window on both browsers.
In additions after the modal is opened "driver.getWindowHandles()" returns only 1 hanlde
which belongs to the main(parent) window. I'm considering to return to Selenium1 because
the application I'm automating relies on many modal popup windows.

This is quite disappointment to find out that Selenium2 can't handle modal windows!

Reported by Ido.Levi1974 on 2012-11-08 21:23:04

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
The Thread trick, was only working for this setup:

browser: IE 9, FIREFOX
Scenario: 
Click on the link to open the popup. 
A modal popup window opens. A separate window not a thick box style window. 
User can not shift focus to Modal window using WebDriver, as WebDriver is expecting
to finish synchronization with the parent window to continue with rest of the code.
But can not continue. 

so my attempt was to fool webdriver to kill the thread of parent synchronization with
the above thread trick.So that it will continue with rest of the code. In my case the
new popup window is identifiable as a new window. Thats because it is a new window.
In case of modal window as it is(like a thick box style), I could actually identify
them as elements on the same page rather a new window, I may be wrong. 

Hope this helps. 

Reported by kalyanparupalli on 2012-11-08 23:23:31

Owner

lukeis commented Mar 2, 2016

The Thread trick, was only working for this setup:

browser: IE 9, FIREFOX
Scenario: 
Click on the link to open the popup. 
A modal popup window opens. A separate window not a thick box style window. 
User can not shift focus to Modal window using WebDriver, as WebDriver is expecting
to finish synchronization with the parent window to continue with rest of the code.
But can not continue. 

so my attempt was to fool webdriver to kill the thread of parent synchronization with
the above thread trick.So that it will continue with rest of the code. In my case the
new popup window is identifiable as a new window. Thats because it is a new window.
In case of modal window as it is(like a thick box style), I could actually identify
them as elements on the same page rather a new window, I may be wrong. 

Hope this helps. 

Reported by kalyanparupalli on 2012-11-08 23:23:31

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Hello,

I also suffer from this issue. I use webdriver 2.25 and IE8.

Has anyone found other workaround since then?

Thanks for your help!

Reported by ductrung.tran on 2012-12-06 16:50:41

Owner

lukeis commented Mar 2, 2016

Hello,

I also suffer from this issue. I use webdriver 2.25 and IE8.

Has anyone found other workaround since then?

Thanks for your help!

Reported by ductrung.tran on 2012-12-06 16:50:41

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Inside window.showModalDialog(); resizable:no not working in Chrome, Actually I want
to hide Maximize & Minimize buttons for chrome, Please send me solution on same.

Thanks,

Reported by yuvrajdhamdhere on 2013-03-05 10:14:55


- _Attachment: [ModelPopup issue.JPG](https://storage.googleapis.com/google-code-attachments/selenium/issue-284/comment-123/ModelPopup issue.JPG)_
Owner

lukeis commented Mar 2, 2016

Inside window.showModalDialog(); resizable:no not working in Chrome, Actually I want
to hide Maximize & Minimize buttons for chrome, Please send me solution on same.

Thanks,

Reported by yuvrajdhamdhere on 2013-03-05 10:14:55


- _Attachment: [ModelPopup issue.JPG](https://storage.googleapis.com/google-code-attachments/selenium/issue-284/comment-123/ModelPopup issue.JPG)_
@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Hi guys, 

In My case, the multithread method that I posted earlier was only working on WebDriver
instance. But not on Remote WebDriver. 

But the Below solution (though its not a great way to deal with this problem, it still
worked for me) 

I am intercepting/overriding the javascript of the page that is responsible for opening
the popup. 

add below lines of code before performing the action that is responsible for opening
the ModalDialog. 

//Override the javascript that opens modaldailog to a normal popup window. So that
the main driver thread can continue to rest of the execution. 

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

// then perform action on the webElement to open popup. 
WebElement.click();


Side Effects:
This code may have side effects in the way that your application works (in my case
it doesn't have any). and this will change the behavior of the popup by making it non
modal dialog. 


Reported by kalyanparupalli on 2013-03-06 00:10:08

Owner

lukeis commented Mar 2, 2016

Hi guys, 

In My case, the multithread method that I posted earlier was only working on WebDriver
instance. But not on Remote WebDriver. 

But the Below solution (though its not a great way to deal with this problem, it still
worked for me) 

I am intercepting/overriding the javascript of the page that is responsible for opening
the popup. 

add below lines of code before performing the action that is responsible for opening
the ModalDialog. 

//Override the javascript that opens modaldailog to a normal popup window. So that
the main driver thread can continue to rest of the execution. 

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

// then perform action on the webElement to open popup. 
WebElement.click();


Side Effects:
This code may have side effects in the way that your application works (in my case
it doesn't have any). and this will change the behavior of the popup by making it non
modal dialog. 


Reported by kalyanparupalli on 2013-03-06 00:10:08

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Hi all,
When can we see any progress in this issue for mozilla? Looks like that this issue
has been there from such a long time! Please investigate...
Below is the script which shows that Mozilla hangs just after the button to invoke
Modal dialog box is clicked. I think same is happening with chrome also. However its
working OK with IE (at least able to recognize a different window handle)

Hope that it will help..

import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

public class ModalDialogBoxTest {

    public static final String URL = "http://developer.mozilla.org/samples/domref/showModalDialog.html";

    public WebDriver driver;

    @Test
    public void modalTest(){

        //System.setProperty("webdriver.ie.driver", "insert ie driver path here");      
        //driver = new InternetExplorerDriver();

        driver = new FirefoxDriver();
        driver.get(URL);

        System.out.println("test starts");
        String currentWindowHandle = driver.getWindowHandle();
        System.out.println("Current Window handle: " +currentWindowHandle);
        WebElement dialogButton = driver.findElement(By.xpath("//input[@value='Open modal
dialog']"));
        String popupWindowHandle  =  getPopupWindowHandle(driver,dialogButton);     
        System.out.println("After Click :: You wont see this message with mozilla");        
        System.out.println("Popup Window Handle: "+popupWindowHandle );

        driver.switchTo().window(popupWindowHandle);

        // do somting in the popup window
        WebElement textbox = driver.findElement(By.cssSelector("#foo"));
        textbox.click();
        textbox.clear();
        textbox.sendKeys("Se");

        // trying to close the popup window but no luck :-(     
        (new WebDriverWait(driver, 5)).
            until(ExpectedConditions.elementToBeClickable(By.xpath("html/body/input[2]")));
        driver.findElement(By.xpath("html/body/input[2]")).click();
        System.out.println("After close");
        driver.switchTo().window(currentWindowHandle);      
    }

    String getPopupWindowHandle(WebDriver driver, WebElement element) {

        String popupHandle = null;
        int maxTimeToWait = 5000;
        int timeInterval = 1000;
        int timeElasped = 0;
        int attempt;

        // get all the window handles before the popup window appears
        Set<String> beforePopup = driver.getWindowHandles();

        // click the link which creates the popup window
        element.click();
        System.out.println("element clicked");

        attempt = 1; 
        while (timeElasped < maxTimeToWait) {

            // get all the window handles after the popup window appears
            Set<String> afterPopup = driver.getWindowHandles();

            // remove all the handles from before the popup window appears
            afterPopup.removeAll(beforePopup);

            // there should be only one window handle left
            if(afterPopup.size() == 1) {
                System.out.println("Popup window found");
                popupHandle = (String)afterPopup.toArray()[0];
                break;
            }           

            try {
                Thread.sleep(timeInterval);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            timeElasped = timeInterval * attempt;
            attempt++;
        }
        if ( popupHandle.isEmpty() || popupHandle == null  )
        {
            System.out.println("No Popup Window found");
        }

        return popupHandle;

    } // end func

} // end class




Reported by sandeep.sethi.selenium on 2013-03-25 17:36:06

Owner

lukeis commented Mar 2, 2016

Hi all,
When can we see any progress in this issue for mozilla? Looks like that this issue
has been there from such a long time! Please investigate...
Below is the script which shows that Mozilla hangs just after the button to invoke
Modal dialog box is clicked. I think same is happening with chrome also. However its
working OK with IE (at least able to recognize a different window handle)

Hope that it will help..

import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

public class ModalDialogBoxTest {

    public static final String URL = "http://developer.mozilla.org/samples/domref/showModalDialog.html";

    public WebDriver driver;

    @Test
    public void modalTest(){

        //System.setProperty("webdriver.ie.driver", "insert ie driver path here");      
        //driver = new InternetExplorerDriver();

        driver = new FirefoxDriver();
        driver.get(URL);

        System.out.println("test starts");
        String currentWindowHandle = driver.getWindowHandle();
        System.out.println("Current Window handle: " +currentWindowHandle);
        WebElement dialogButton = driver.findElement(By.xpath("//input[@value='Open modal
dialog']"));
        String popupWindowHandle  =  getPopupWindowHandle(driver,dialogButton);     
        System.out.println("After Click :: You wont see this message with mozilla");        
        System.out.println("Popup Window Handle: "+popupWindowHandle );

        driver.switchTo().window(popupWindowHandle);

        // do somting in the popup window
        WebElement textbox = driver.findElement(By.cssSelector("#foo"));
        textbox.click();
        textbox.clear();
        textbox.sendKeys("Se");

        // trying to close the popup window but no luck :-(     
        (new WebDriverWait(driver, 5)).
            until(ExpectedConditions.elementToBeClickable(By.xpath("html/body/input[2]")));
        driver.findElement(By.xpath("html/body/input[2]")).click();
        System.out.println("After close");
        driver.switchTo().window(currentWindowHandle);      
    }

    String getPopupWindowHandle(WebDriver driver, WebElement element) {

        String popupHandle = null;
        int maxTimeToWait = 5000;
        int timeInterval = 1000;
        int timeElasped = 0;
        int attempt;

        // get all the window handles before the popup window appears
        Set<String> beforePopup = driver.getWindowHandles();

        // click the link which creates the popup window
        element.click();
        System.out.println("element clicked");

        attempt = 1; 
        while (timeElasped < maxTimeToWait) {

            // get all the window handles after the popup window appears
            Set<String> afterPopup = driver.getWindowHandles();

            // remove all the handles from before the popup window appears
            afterPopup.removeAll(beforePopup);

            // there should be only one window handle left
            if(afterPopup.size() == 1) {
                System.out.println("Popup window found");
                popupHandle = (String)afterPopup.toArray()[0];
                break;
            }           

            try {
                Thread.sleep(timeInterval);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            timeElasped = timeInterval * attempt;
            attempt++;
        }
        if ( popupHandle.isEmpty() || popupHandle == null  )
        {
            System.out.println("No Popup Window found");
        }

        return popupHandle;

    } // end func

} // end class




Reported by sandeep.sethi.selenium on 2013-03-25 17:36:06

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Strange!! No response!!

Reported by sandeep.sethi.selenium on 2013-04-01 09:05:33

Owner

lukeis commented Mar 2, 2016

Strange!! No response!!

Reported by sandeep.sethi.selenium on 2013-04-01 09:05:33

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Issue 4452 has been merged into this issue.

Reported by barancev on 2013-04-11 07:50:17

Owner

lukeis commented Mar 2, 2016

Issue 4452 has been merged into this issue.

Reported by barancev on 2013-04-11 07:50:17

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
On the no release 2.32 is the bug with modal dialog from Issue 4582 still exists!
But now both tests will not work. 

Reported by tiran1984 on 2013-04-12 11:35:03

Owner

lukeis commented Mar 2, 2016

On the no release 2.32 is the bug with modal dialog from Issue 4582 still exists!
But now both tests will not work. 

Reported by tiran1984 on 2013-04-12 11:35:03

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
For us this issue is not an enhancement request but a major bug report.
And we're waiting for a final fix for such a long time (this issue has been created
in 2009) .

For every new selenium release we have to patch the jars in order to workaround this
issue.

We're really looking forward to seeing this finally fixed.

Reported by patric@rufflar.com on 2013-05-23 15:23:29

Owner

lukeis commented Mar 2, 2016

For us this issue is not an enhancement request but a major bug report.
And we're waiting for a final fix for such a long time (this issue has been created
in 2009) .

For every new selenium release we have to patch the jars in order to workaround this
issue.

We're really looking forward to seeing this finally fixed.

Reported by patric@rufflar.com on 2013-05-23 15:23:29

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Would you please share the patch and tell which browsers are fixed by the patch?

Reported by barancev on 2013-05-23 15:30:22

Owner

lukeis commented Mar 2, 2016

Would you please share the patch and tell which browsers are fixed by the patch?

Reported by barancev on 2013-05-23 15:30:22

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
As a workaround (for Firefox), I have been using Firebug's Copy XPath/CSS to get to
the elements in the modal -- highlight field and right-click to bring up the context
menu. 

Experientially, WebDriver's switchTo.activeElement() works if the modal has but a single
widget. If said modal has multiple fields then using Firebug's Copy XPath/CSS as input
to WebDriver's findElements(By by) works for me ... rather ugly but it is a workaround.

Reported by isaac.riley@fluentmedical.com on 2013-05-29 18:00:58

Owner

lukeis commented Mar 2, 2016

As a workaround (for Firefox), I have been using Firebug's Copy XPath/CSS to get to
the elements in the modal -- highlight field and right-click to bring up the context
menu. 

Experientially, WebDriver's switchTo.activeElement() works if the modal has but a single
widget. If said modal has multiple fields then using Firebug's Copy XPath/CSS as input
to WebDriver's findElements(By by) works for me ... rather ugly but it is a workaround.

Reported by isaac.riley@fluentmedical.com on 2013-05-29 18:00:58

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Issue 5748 has been merged into this issue.

Reported by barancev on 2013-06-11 20:48:05

Owner

lukeis commented Mar 2, 2016

Issue 5748 has been merged into this issue.

Reported by barancev on 2013-06-11 20:48:05

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Issue 5748 has been merged into this issue.

Reported by barancev on 2013-06-11 20:50:41

Owner

lukeis commented Mar 2, 2016

Issue 5748 has been merged into this issue.

Reported by barancev on 2013-06-11 20:50:41

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Hi all,

A workaround working for me on Firefox for the same issue - to use an async click,
by for example JavaScript setTimeout.

So instead of

element.click

use something like

driver.execute_script('var el=arguments[0]; setTimeout(function() { el.click(); },
100);', element)

Hope it helps, as it is quite straightforward - until this issue will be fixed.

Reported by denis@mingulov.com on 2013-09-07 13:47:50

Owner

lukeis commented Mar 2, 2016

Hi all,

A workaround working for me on Firefox for the same issue - to use an async click,
by for example JavaScript setTimeout.

So instead of

element.click

use something like

driver.execute_script('var el=arguments[0]; setTimeout(function() { el.click(); },
100);', element)

Hope it helps, as it is quite straightforward - until this issue will be fixed.

Reported by denis@mingulov.com on 2013-09-07 13:47:50

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Thanks a lot de...@mingulov.com

Your solution really works for Mozilla!

JavascriptExecutor executor = (JavascriptExecutor)getDriver();
executor.executeScript("var el=arguments[0]; setTimeout(function() { el.click(); },
100);", stateOfSale);

Reported by samsonovanton on 2013-10-22 19:29:15

Owner

lukeis commented Mar 2, 2016

Thanks a lot de...@mingulov.com

Your solution really works for Mozilla!

JavascriptExecutor executor = (JavascriptExecutor)getDriver();
executor.executeScript("var el=arguments[0]; setTimeout(function() { el.click(); },
100);", stateOfSale);

Reported by samsonovanton on 2013-10-22 19:29:15

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
we can solve the showModeDialog  with the code following:
as we know our dialog have a frame or iframe,so we must let foucus to the frame.

/**
     * select frame by frame index when the element witch is in the frame is present
     * @param selenium
     * @param xPath
     * @param driver
     * @param isPopUpWindow
     * @param loopTimes
     * @throws Exception
     * @author xpeng
     * @see
     */
    public static void selectFrameByIndexTillElementPresent(Selenium selenium, String
xPath, WebDriver driver,
            boolean isPopUpWindow, Integer loopTimes)
        throws Exception {
        boolean foundFlag = false;
        int foundTimes = 0;
        Thread.sleep(300);
        if(loopTimes == null) {
            loopTimes = 10;
        }
        try {
            while (foundTimes < loopTimes && !foundFlag) {
                if (!SeleniumHelper.isSupportMutiBrowser() && driver != null) {
                    if (isPopUpWindow) {
                        String mainWindow = driver.getWindowHandle();
                        Set<String> strs = driver.getWindowHandles();
                        for (String string : strs) {
                            if (mainWindow.equals(string)) {
                                continue;
                            }
                            driver = driver.switchTo().window(string);
                            if (SeleniumHelper.isElementPresent(xPath, selenium)) {
                                foundFlag = true;
                                break;
                            } else {
                                foundFlag = false;
                            }
                        }
                        int frameNum = SeleniumHelper.getNumberOfElements("//frame", selenium);
                        if (frameNum > 0) {
                            selenium.selectFrame("index=0");
                            if (SeleniumHelper.isElementPresent(xPath, selenium)) {
                                foundFlag = true;
                            }
                        }
                    } else {
                        String mainWindow = driver.getWindowHandle();
                        driver = driver.switchTo().window(mainWindow);
                        int frameNum = SeleniumHelper.getNumberOfElements("//iframe", selenium);
                        for (int i = 0; i < frameNum; i++) {
                            driver = driver.switchTo().window(mainWindow);
                            selenium.selectFrame("index=" + i);
                            if (SeleniumHelper.isElementPresent(xPath, selenium)) {
                                foundFlag = true;
                                break;
                            } else {
                                foundFlag = false;
                            }
                        }
                    }
                } else {
                    try {
                        selenium.selectWindow(null);
                    } catch (Exception e) {
                    }
                    int iframeNum = SeleniumHelper.getNumberOfElements("//iframe", selenium);
                    for (int i = iframeNum - 1; i >= 0; i--) {
                        selenium.selectWindow(null);
                        selenium.selectFrame("index=" + i);
                        if (SeleniumHelper.isElementPresent(xPath, selenium)) {
                            foundFlag = true;
                            break;
                        } else {
                            foundFlag = false;
                        }
                    }
                }
                Thread.sleep(300);
                foundTimes++;
            }
        } catch (Exception e) {
            if (!SeleniumHelper.isSupportMutiBrowser()) {
                selenium.selectWindow(null);
            } else {
                selenium.selectFrame("index=0");
            }
        }
    }

Reported by abc515666266 on 2013-12-13 08:58:42

Owner

lukeis commented Mar 2, 2016

we can solve the showModeDialog  with the code following:
as we know our dialog have a frame or iframe,so we must let foucus to the frame.

/**
     * select frame by frame index when the element witch is in the frame is present
     * @param selenium
     * @param xPath
     * @param driver
     * @param isPopUpWindow
     * @param loopTimes
     * @throws Exception
     * @author xpeng
     * @see
     */
    public static void selectFrameByIndexTillElementPresent(Selenium selenium, String
xPath, WebDriver driver,
            boolean isPopUpWindow, Integer loopTimes)
        throws Exception {
        boolean foundFlag = false;
        int foundTimes = 0;
        Thread.sleep(300);
        if(loopTimes == null) {
            loopTimes = 10;
        }
        try {
            while (foundTimes < loopTimes && !foundFlag) {
                if (!SeleniumHelper.isSupportMutiBrowser() && driver != null) {
                    if (isPopUpWindow) {
                        String mainWindow = driver.getWindowHandle();
                        Set<String> strs = driver.getWindowHandles();
                        for (String string : strs) {
                            if (mainWindow.equals(string)) {
                                continue;
                            }
                            driver = driver.switchTo().window(string);
                            if (SeleniumHelper.isElementPresent(xPath, selenium)) {
                                foundFlag = true;
                                break;
                            } else {
                                foundFlag = false;
                            }
                        }
                        int frameNum = SeleniumHelper.getNumberOfElements("//frame", selenium);
                        if (frameNum > 0) {
                            selenium.selectFrame("index=0");
                            if (SeleniumHelper.isElementPresent(xPath, selenium)) {
                                foundFlag = true;
                            }
                        }
                    } else {
                        String mainWindow = driver.getWindowHandle();
                        driver = driver.switchTo().window(mainWindow);
                        int frameNum = SeleniumHelper.getNumberOfElements("//iframe", selenium);
                        for (int i = 0; i < frameNum; i++) {
                            driver = driver.switchTo().window(mainWindow);
                            selenium.selectFrame("index=" + i);
                            if (SeleniumHelper.isElementPresent(xPath, selenium)) {
                                foundFlag = true;
                                break;
                            } else {
                                foundFlag = false;
                            }
                        }
                    }
                } else {
                    try {
                        selenium.selectWindow(null);
                    } catch (Exception e) {
                    }
                    int iframeNum = SeleniumHelper.getNumberOfElements("//iframe", selenium);
                    for (int i = iframeNum - 1; i >= 0; i--) {
                        selenium.selectWindow(null);
                        selenium.selectFrame("index=" + i);
                        if (SeleniumHelper.isElementPresent(xPath, selenium)) {
                            foundFlag = true;
                            break;
                        } else {
                            foundFlag = false;
                        }
                    }
                }
                Thread.sleep(300);
                foundTimes++;
            }
        } catch (Exception e) {
            if (!SeleniumHelper.isSupportMutiBrowser()) {
                selenium.selectWindow(null);
            } else {
                selenium.selectFrame("index=0");
            }
        }
    }

Reported by abc515666266 on 2013-12-13 08:58:42

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Thank you de...@mingulov.com! Your solution worked for Firefox. Do we have any plan
to resolve this for Firefox and Chrome?

Reported by SitamJana on 2014-04-22 10:23:19

Owner

lukeis commented Mar 2, 2016

Thank you de...@mingulov.com! Your solution worked for Firefox. Do we have any plan
to resolve this for Firefox and Chrome?

Reported by SitamJana on 2014-04-22 10:23:19

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
+1 for my vote.. This defect should be fixed in Selenium core itself.

Reported by way2ashoo on 2014-04-29 08:09:03

Owner

lukeis commented Mar 2, 2016

+1 for my vote.. This defect should be fixed in Selenium core itself.

Reported by way2ashoo on 2014-04-29 08:09:03

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
I had the same problem, but using Capybara ( https://github.com/jnicklas/capybara )together
with selenium solved it (for firefox at least). Capybara must have found some working
work-around to handle the problem with modal dialogs. 

Reported by ragnhild.karlsson on 2014-07-10 08:07:17

Owner

lukeis commented Mar 2, 2016

I had the same problem, but using Capybara ( https://github.com/jnicklas/capybara )together
with selenium solved it (for firefox at least). Capybara must have found some working
work-around to handle the problem with modal dialogs. 

Reported by ragnhild.karlsson on 2014-07-10 08:07:17

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Issue 7667 has been merged into this issue.

Reported by barancev on 2014-07-28 19:38:21

Owner

lukeis commented Mar 2, 2016

Issue 7667 has been merged into this issue.

Reported by barancev on 2014-07-28 19:38:21

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
Hi #134 de...@mingulov.com,

I can open the dialog using your workaround, but the element in the opened dialog still
can't be located, Do you know is there anything special to locate the element on the
opened dialog?


Hi all,

A workaround working for me on Firefox for the same issue - to use an async click,
by for example JavaScript setTimeout.

So instead of

element.click

use something like

driver.execute_script('var el=arguments[0]; setTimeout(function() { el.click(); },
100);', element)

Hope it helps, as it is quite straightforward - until this issue will be fixed.



Reported by michelle.juaner on 2015-01-14 05:33:00

Owner

lukeis commented Mar 2, 2016

Hi #134 de...@mingulov.com,

I can open the dialog using your workaround, but the element in the opened dialog still
can't be located, Do you know is there anything special to locate the element on the
opened dialog?


Hi all,

A workaround working for me on Firefox for the same issue - to use an async click,
by for example JavaScript setTimeout.

So instead of

element.click

use something like

driver.execute_script('var el=arguments[0]; setTimeout(function() { el.click(); },
100);', element)

Hope it helps, as it is quite straightforward - until this issue will be fixed.



Reported by michelle.juaner on 2015-01-14 05:33:00

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
hi all,

I use executeScript, my modal window opens but it closes immediatly after.
My code is :

executor.executeScript("var el = document.getElementById('.active_line #colo_0 > a
> #zoom'); setTimeout(function() { el.click(); }, 1000); setTimeout(function(){document.getElementById('CLI_LBMAG_0').click();},1000);");

I click on my button and after i want to click on an Element in my modal window.
Any idea?

Reported by chautard.jonathan on 2015-02-10 10:18:24

Owner

lukeis commented Mar 2, 2016

hi all,

I use executeScript, my modal window opens but it closes immediatly after.
My code is :

executor.executeScript("var el = document.getElementById('.active_line #colo_0 > a
> #zoom'); setTimeout(function() { el.click(); }, 1000); setTimeout(function(){document.getElementById('CLI_LBMAG_0').click();},1000);");

I click on my button and after i want to click on an Element in my modal window.
Any idea?

Reported by chautard.jonathan on 2015-02-10 10:18:24

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner
this functionality seems to have been deprecated from the standards:
https://developer.mozilla.org/en-US/docs/Web/API/Window/showModalDialog

close issue?

Reported by alejandro.moncayo on 2015-08-31 03:54:46

Owner

lukeis commented Mar 2, 2016

this functionality seems to have been deprecated from the standards:
https://developer.mozilla.org/en-US/docs/Web/API/Window/showModalDialog

close issue?

Reported by alejandro.moncayo on 2015-08-31 03:54:46

@lukeis

This comment has been minimized.

Show comment Hide comment
@lukeis

lukeis Mar 2, 2016

Owner

Reported by luke.semerau on 2015-09-17 17:44:23

  • Labels added: Restrict-AddIssueComment-Commit
Owner

lukeis commented Mar 2, 2016

Reported by luke.semerau on 2015-09-17 17:44:23

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis locked and limited conversation to collaborators Mar 3, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.