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
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.
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
Comment #11 on issue 284 by dhar...@google.com: Support for
window.showModalDialog
http://code.google.com/p/selenium/issues/detail?id=284
(No comment was entered for this change.)
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....
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?
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
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().
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??
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.
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 :'(
James Evans has posted a changelist that aims at solving this issue for the
IE driver.
Look for r11989 and recompile the driver for testing! Thanks James!
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!
I tried to use the new driver dll that James posted, but now IE won't start
in WebDriver, any thoughts?
What do you mean by "IE doesn't start"? Do you receive any error messages?
What does your test code look like?
I'm using the python driver, and I replaced the old IEDriver.dll with the
new, I tried to run the unit test and it just sits on import of modules,
and IE is never launched to executed the unit test. I'm a noob to the
webdriver side of selenium so I don't know how to enable the logging
object, if you could point in the right direct for python I'd be happy to
provide that
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?
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).
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.
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.
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!
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");
Issue 1839 has been merged into this issue.
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=Fieldglass: Associate Sites to Master Document");
selenium.selectWindow("title=Fieldglass: 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
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");
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.
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.
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
I believe this is somewhat related to issue 1828 where you can find some
possible work-arounds:
https://code.google.com/p/selenium/issues/detail?id=1828#c19
Comment #38 on issue 284 by barancev: Support for window.showModalDialog
http://code.google.com/p/selenium/issues/detail?id=284
(No comment was entered for this change.)
I have had the same problem as well and am running on Windows 7, IE 8 and
Selenium 2.12.0.
Please take a look at the following gist URL which basically has the html
pages required to simulate the problem, a sample java code which can be
used to simulate the problem and also the error.
Was wondering if someone can please help take a look at this issue ?
Gist URL : https://gist.github.com/1404611
I am using Robot Framework + Selenium2Library + Selenium/WebDriver 2.8.1 +
IE8 + Win 7, it seems that WebDriver already can handle doShowModalDialog
nicely. What you need to do is only to use Select Window keyword to switch
between modal and main window, although you may need to Select Window
multiple times, first few times may fail
"As for issue 284, that issue simple asks for adding support for
showModalDialog() windows. This has been done for IE. I do not know about
other browsers."
If this is the case, then I can not seem to figure out what I am doing
wrong w/ my c#.NET code.
In my test, I have to click on a button in IE8( "search") which has an
onclick = "return openSearchDialog();"
openSearchDialog(); then fires a showModalDialog(); within, which loads a
modal with an iframe within it.
no matter what i do, I cannot seem to focus within the modal or iframe.
"As for issue 284, that issue simple asks for adding support for
showModalDialog() windows. This has been done for IE. I do not know about
other browsers."
If this is the case, then I can not seem to figure out what I am doing
wrong.
In my test, I have to click on a button in IE8( "search") which has an
onclick = "return openSearchDialog();"
openSearchDialog(); then fires a showModalDialog(); within, which loads a
modal with an iframe within it.
no matter what i do, I cannot seem to focus within the modal or iframe.
Can anybody lend ANY advice on how to get past this issue?
Does anybody fixed this issue in Selenium IDE for Firefox 8?
@christopher.baker1988 The base case is working for simple
showModalDialog() windows on IE. It may be possible that showModalDialog()
windows that contain iframes is not. If you want to open a new issue to
track that particular case (showModalDialog() windows with iframes not
working in IE), it can be worked on in due course, provided you supply a
reproducible test case (including a set of HTML files to test against).
Without the repro case, however, it's unlikely we'll be able to correctly
solve the problem to your satisfaction.
catch same problem :( , I tried to update to 2.15 but it doesn't help, some
additional info:
FF and Chrome stuck in click call.
IE move on, but list of window handlers same as before click call.
Any ideas?
The IE driver should now handle showModalDialog() windows with frames or
iframes as of r15250. This change will also be included when 2.16.0 is
released. If it doesn't solve your issue with showModalDialog() windows
with frames or iframes, do not report that failure as a comment in this
issue; instead, please open a new issue with a repro case.
@james That's great news! Any idea when that release is going to take place?
I also noticed FF get stucked in my showModalDialog test case, I am using
2.8
Just downloaded 2.16.0, no information about this bug fix in the release
notes.
Just tried one scenario, It says "No window found".
@James - Is this issue fixed in 2.16.0?
The bug status still reads "New" so I dont think this is fixed yet !
This issue is incredibly broad. It doesn't specify that it should be
implemented only in IE, so it can't be set to "Fixed". If we believe we've
fully implemented it for IE, and close the issue, surely someone would
complain that it's not implemented in Firefox or Chrome.
Yes, I can say definitively that you should now be able to use
showModalDialog() windows with IE; indeed, many people are already
successfully doing so. I can also confirm that the fix for problems people
were having accessing elements in frames/iframes in showModalDialog()
windows is included in 2.16.
@James - Thank you for the update (Fixed on IE).
I have tested on IE with 2.16, still Webdriver not able to identify the
model pop-up.
In my application model popup is invoked in the following way(.Net):
var val = window.showModalDialog(url + '?Ids=' + Id, null, 'dialogHeight:
600px; dialogWidth: 850px,dialogTop: 190px; dialogLeft: 120px; edge:
Raised; center: Yes;help: No; resizable: No; status: No;');
I have used following code to find all the window handles, Size is always
1. Following is the Webdriver code
driver.findElement(By.id("ctl00_CphePurchase_lnkCategory")).click();
Wait(10000); //Wait to load model pop-up
Set<String> availableWindows = driver.getWindowHandles();
Print("Handle Size: " +availableWindows.size());
The issue here is the thread that invokes the action "a click" which opens
a modal dialog gets stuck. I was able to get around this problem by
creating a new thread that would perform the "click" and then sacrifice it.
So the pseudo code is like this..
1. Select the button to click (Main Thread)
2. Create and start a new thread (that has a handle to the button) and
click. This thread will block (and I will so call it sacrificial thread)
3. If required wait for the modal-popup to open and continue to process
other Selenium statements.
If anyone needs a code example feel free to touchbase.
@arindam
I have tested the model-popup as per your above comments, not successful.
Tested on IE - 2.16.1, below is my code, please correct me if I have not
understood your comments properly.
WebDriver driver1;
driver1 = driver;
driver1.findElement(By.id("alnkRequester")).click(); //Activate Model
popup
Wait(10000);//Wait to load model pop-up
driver.findElement(By.id("txtSearchtext")).sendKeys("Bharath");
//Model popup element
Hello All,
Please let me know If any one successful in handling the Model-Dialog on IE
and 2.16.1 invoked by the following code(.Net application).
var val = window.showModalDialog(url + '?Ids=' + Id, null, 'dialogHeight:
600px; dialogWidth: 850px,dialogTop: 190px; dialogLeft: 120px; edge:
Raised; center: Yes;help: No; resizable: No; status: No;');
Regards,
Bharath
Hello All,
I have gone through the Microsoft site to understand how model pop-up is
created. It says
When Windows Internet Explorer opens a window from a modal or modeless HTML
dialog box by using the showModalDialog method or by using the
showModelessDialog method, Internet Explorer uses Component Object Model
(COM) to create a new instance of the window. Typically, the window is
opened by using the first instance of an existing Internet Explorer
process. When Internet Explorer opens the window in a new process, all the
memory cookies are no longer available, including the session ID. This
process is different from the process that Internet Explorer uses to open a
new window by using the open method.
http://msdn.microsoft.com/en-us/library/ms536759(VS.85).aspx
Regards,
Bharath
Hello All,
In the below link it is mentioned that there is a workaround using Ruby -
Fork (Cloning the current process), he also says that it is not possible in
Java.
http://code.google.com/u/114873496028287600096/updates
Did any one try in Java?
I am desperately trying to find a solution, major flow is getting blocked
in my application.
Regards,
Bharath.
Hello All,
http://code.google.com/u/114873496028287600096/updates
I too am getting the same results as bharath when i try to print the window
handles.
I even tried clicking the button by sending a space on the element so that
the call does not get blocked but there is only one window handle printed.
This too is blocking me since all windows that open in my application are
modal windows.
I came across the following post on MSDN blog, this can provide an idea on
how to handle the dialog using COM.
I tested the modal window as part of migration to selenium 2 and firstly
was very happy that I got handle to modal window and can switch to modal
and fill fields and submit buttons on modal page. As I found later this
work only when I'm running test in debug mode in Eclipse. But why,I don't
know ? And I found that in my test which open 5times modal popup running in
debug rarely in some opening window hang (I didn't get the handle to
windows)
@barath.raj.reddy I'm still waiting a sample set of HTML pages that
reproduces the problem as described in comments 52, 54, and 56. Regarding
comment 60, if you examine the C++ code that defines the core of the IE
driver's functionality, you'll see that the methods described in the blog
post you reference are virtually identical to those we use in the driver.
This has been the case since showModalDialog() support was added to the IE
driver, with the only difference being that we use the EnumWindows() API
which is functionally equivalent to using the EnumChildWindows() API with
the desktop window handle as the parent.
@james.
https://developer.mozilla.org/samples/domref/showModalDialog.html
should reproduce the problem for you to test.
@James - I have sent HTML pages to your email.
@bharath I've received your email, and am able to successfully switch to
and manipulate the modal dialog.
James, can you post the code that Bharath sent you and your code that
interacted with the modal window.
( I believe Bharath is looking at a java based solution.)
Thanks
Shrikant
@sk1 - Java code sent by James for my Modal dialog, still I did't try this
on my application.
[Test]
public void ModalTest()
{
// Assume "driver" is a properly instantiated
InternetExplorerDriver instance.
driver.Url = "http://localhost/modal/modal.html";
IWebElement element =
driver.FindElement(By.Id("ctl00_CphePurchase_btnSelectVendor1"));
element.Click();
// Wait for the number of window handles to be greater than 1,
or a timeout.
DateTime timeoutEnd = DateTime.Now.Add(TimeSpan.FromSeconds(5));
while (driver.WindowHandles.Count == 1 && DateTime.Now <
timeoutEnd)
{
System.Threading.Thread.Sleep(100);
}
// Save the current window handle, and switch to the newly
opened one.
string currentHandle = driver.CurrentWindowHandle;
foreach (string handle in driver.WindowHandles)
{
if (handle != currentHandle)
{
driver.SwitchTo().Window(handle);
break;
}
}
// If we've gotten to this point without switching windows,
this will
// throw an exception. In my case, it does not, if I'm able to
ignore
// the JavaScript compiler errors.
driver.FindElement(By.Id("vmmComponent_txtBCompanyName")).SendKeys("Bharath");
driver.Close();
driver.SwitchTo().Window(currentHandle);
this is a c# code.
Anyways I had tried the same thing in java... with the exception of
while (driver.WindowHandles.Count == 1 && DateTime.Now < timeoutEnd)
{
System.Threading.Thread.Sleep(100);
}
I wonder if that did the trick.
Do you think using c# drivers instead of java could have made the
difference ?
Anyways, when you try ( and if you do that in Java) please post your code
if you could confirm if it works on
https://developer.mozilla.org/samples/domref/showModalDialog.html
it would be great.
Thanks,
Shrikant
@James - Thank you for solving this issue on IE (I have tested only on IE)
Java code for handling IE Modal dialog
http://msdn.microsoft.com/en-us/library/ms536759(VS.85).aspx
I hope following example will help you to solve the issue.
driver.findElement(By.id("ctl00_CphePurchase_lnkCategory")).click();
//Open Modal dialog
Wait(9000);
driver.getWindowHandles();
Set<String> availableWindows = driver.getWindowHandles();
Print("Handle Size:" +availableWindows.size());
int Windows = 2;
if (availableWindows.size()==Windows) {
// For loop for modal popup
for (String windowId : availableWindows) {
if ("Select Product &
Category".equals(driver.switchTo().window(windowId).getTitle())){
Print("Modal popup:"+driver.getTitle());
driver.findElement(By.id("chk_PASID_94135508")).click();
driver.findElement(By.id("btnDown")).click();
break; // Task completed, just come out
}
}
// For loop back to parent
for (String windowId : availableWindows) {
driver.switchTo().window(windowId);
if
(("Requisition".equals(driver.switchTo().window(windowId).getTitle()))){
Print("Parent Window:"+driver.getTitle());
break; // Task completed, just come out
}
}
}
else
{
Print("No popups found"); //Implement assertion
}
@James - Thank you for solving this issue on IE (I have tested only on IE)
Java code for handling IE Modal dialog
http://msdn.microsoft.com/en-us/library/ms536759(VS.85).aspx
I hope following example will help you to solve the issue.
driver.findElement(By.id("ctl00_CphePurchase_lnkCategory")).click();
//Open Modal dialog
Wait(9000); // Wait for popup. Need to optimize the code
@James - Thank you for solving this issue on IE (I have tested only on IE)
Java code for handling IE Modal dialog
http://msdn.microsoft.com/en-us/library/ms536759(VS.85).aspx
I hope following example will help you to solve the issue.
driver.findElement(By.id("ctl00_CphePurchase_lnkCategory")).click();
//Open Modal dialog
Wait(9000); // Wait for popup. Need to optimize the code
driver.getWindowHandles();
Set<String> availableWindows = driver.getWindowHandles();
Print("Handle Size:" +availableWindows.size());
int Windows = 2;
if (availableWindows.size()==Windows) {
// For loop for modal popup
for (String windowId : availableWindows) {
if ("Select Product &
Category".equals(driver.switchTo().window(windowId).getTitle())){
Print("Modal popup:"+driver.getTitle());
driver.findElement(By.id("chk_PASID_94135508")).click();
driver.findElement(By.id("btnDown")).click();
break; // Task completed, just come out
}
}
// For loop back to parent
for (String windowId : availableWindows) {
@sk176h Unless you're just looking for public proof that the feature works
in IE, I'm not sure what the fixation is with the developer.mozilla.org
site, as the feature has been tested successfully against other sites using
showModalDialog() windows. The .NET bindings have unit tests that
specifically test handling of showModalDialog() windows. Cases where the
handling them in IE doesn't work tend to be unique to the specific set of
pages, which is why I repeatedly ask for a reproducible case.
Nevertheless, I've posted a complete example using the .NET bindings, C#,
NUnit, and using the Mozilla.org site posted at
https://gist.github.com/1642921. Furthermore, to help those who are most
comfortable in Java, I've tried to annotate the example with comments
indicating what similar Java constructs would be.
@James - For IE & Java, I need to use following statements to get the all
window handles
driver.getWindowHandles();
Set<String> availableWindows = driver.getWindowHandles();
If I just use following statement, I get only one handle. This was reason
why I failed to get the modal dialog handle initially.
Set<String> availableWindows = driver.getWindowHandles();
Is it an issue with the Java bindings? Please clarify.
@James - For IE & Java, I need to use following statements to get the all
window handles
driver.getWindowHandles();
Set<String> availableWindows = driver.getWindowHandles();
Print("Handle Size:" +availableWindows.size());
If I just use following statement, I get only one handle. This was reason
why I failed to get the modal dialog handle initially.
Set<String> availableWindows = driver.getWindowHandles();
Print("Handle Size:" +availableWindows.size());
It's most assuredly not the Java bindings. All of the language bindings
delegate to the same C++ code under the covers. For whatever reason, the
first time you call getWindowHandles(), the dialog hasn't had time for
WebDriver to register it. By the second time you call getWindowHandles(),
it is. I realize you're using a 9000 millisecond sleep to wait for the
dialog to appear, and as far as I'm aware, this should be enough; however,
it's not working in this case, and it's not good practice for something
like this anyway. It's possible the long sleep is preventing the correct
detection of the modal dialog after the click. Rather than a single large
sleep, you should be polling for changes at a small interval. You can see
this in the example posted here, and at github. You can code such a wait
yourself, as I've done here, or use the WebDriverWait class to accomplish
the same thing.
@james - Thanks for the update, I will implement polling for small interval
time.
@Bharath Or Anyone , please help me on this issue -
I used the below code which was suggested by Bharat to get handle on the
pop up and access the elements on the popup window.
Using the below code , I could get the pop-up window title OR pop-up URL as
u could see the print statements.
But when i coded like -
driver.findElement(By.id("ins_id")).sendKeys("0.2");, it is not setting the
value in the respective text box in the pop-up!! ( I copied the small
snippet of DOM source at the end of this below code )
-------------------------------------------------------------------
driver.getWindowHandles();
Set<String> availableWindows = driver.getWindowHandles();
System.out.println("Handle Size:" +availableWindows.size());
int Windows = 2;
if (availableWindows.size()==Windows)
{
// For loop for modal popup
for (String windowId : availableWindows)
{
if ("pop up
title".equals(driver.switchTo().window(windowId).getTitle()))
{
System.out.println("Modal popup:"+driver.getTitle());
System.out.println( " driver.getCurrentUrl --> " +
driver.getCurrentUrl()); // this is fine...returning correctly
System.out.println( " driver.get title --> " +
driver.getTitle()); // this is fine
System.out.println( " driver.get wndw hndle
--> " + driver.getWindowHandle());
driver.findElement(By.id("ins_id")).sendKeys("0.2"); // not
working..."ins_id" is the id of the text field in the popup window
driver.findElement(By.xpath( "//input[@id='ins_id']")).sendKeys("0.1"); //
//not working
-------------------------------------------------------------------------------
DOM source :
--------------
<input name="ins_name"
title="ins_title"
class="NormalField" id="ins_id" style="width: 55px;"
type="text" maxLength="8"
LabelControl="ins_lbl" ClientName="ins_client"/>
This is .NET application. My OS is Windows 7 Professional. jar file :
selenium-server-standalone-2.17.0.jar
Any suggestions is greatly appreciated!
Thanks James,
I think we were missing the polling logic. I used polling and it works like
a charm
Thanks,
Shrikant
I tried ti use the following example without success. In general when I'm
using the default method in IE webdriver doesn't see the window.
Here is my test -
@Test
public void verifySetCreation() throws InterruptedException {
loginPage.loginAsUser(login, password);
Thread.sleep(9000);
driver.switchTo().window("ModalWindowHack");
getPagesManager().getEditSetItemDialog().addClaim("auto", "bikes");
getPagesManager().getEditSetItemDialog().getOkButton().click();
}
The window is opened and full stop. (:
Window not found.
I need help.
I tried ti use the following example without success. In general when I'm
using the default method in IE webdriver doesn't see the window.
Here is my test -
@Test
public void verifySetCreation() throws InterruptedException {
loginPage.loginAsUser(login, password);
getPagesManager().getSetPage().getAddManuallyButton().click();
Thread.sleep(1000);
A showModalDialog() window doesn't have a name, so switching to it by name
will not work. You will have to use the WebDriver window identifier
(or "handle"). Additionally, the use of a straight Thread.sleep() is not
likely to work either. You'll need to implement some polling logic either
using WebDriverWait, or something similar to (a Java version of) the code
posted at the github gist referenced above[1].
I am facing a wired problem of selenium identify the elements under model
window as hidden. Even though the element is clearly available for the user
interaction. I am using Win XP,7 Selenium 2.17 IE 8,9
I just upgraded to Selenium 2.18 and i am getting an
org.openqa.selenium.UnhandledAlertException
when i try to do getWindowHandles on the IE Driver object.
Has something changed between implementations
Thank all for the comments. The issue was fixed using "handles". After that
webdriver works with modal window's fields, but doesn't work with OK and
Cancel controls on the window. Please note that it worked fine before.
After installing 2.18 the fix failed and the window is invisible.
Any ideas?
I am having the same problem as sk1. After upgrading to selenium 2.18 I
receive a
org.openqa.selenium.UnhandledAlertException: Modal dialog present
when I try to do getWindowHandles in IE. I cannot interact with anything on
the main window or the modal dialog. Previously I would switch to the modal
dialog and interact with it using
driver.switchTo().window(windowhandle);
It allows me to switch to modal using
driver.switchTo().alert()
but I cannot interact with the page like I previously was able to (update
input boxes, drop down menus, etc). Any ideas how to get around this now?
2.18 has been changed to deal with unhandled alerts [1].
It was discussed on the dev list [2] and agreed that all requests should be
blocked if a modal present, exept for the requests that deal with the
modal. Sounds like it is too strict -- window manipulation requests should
be excluded from this rule too. This will be fixed in 2.19.
[1] http://code.google.com/p/selenium/source/browse/trunk/java/CHANGELOG
[2] https://groups.google.com/forum/#!topic/selenium-developers/9_hK0O4Qpe8
It was the good idea to handle alerts but if modal dialog window popup
populate then driver.getWindowHandles(); throwing UnhandledAlertException
I m facing problem on modal dialog window popup if alert present on it and
i use driver.switchto().alert().accept(); then webdriver throwing exception
ie; NoAlertPresentException
The app opens another window after entering in a link, if i attempt to
change the url then the destination page doesnt seem to get that there is a
logged user.
if i could switch the window back to the first one then i could easily
re-write the url as i did in firefox.
maybe there is a hack to this bug using win32gui?
I see that UnhandledAlertException shouldn't be triggered by a modal dialog
window as of r15807. Are there plans for a similar interface for unhandled
modal windows at this time?
I am using 2.16 and my scripts are running fine.
Just downloaded 2.19 and ran the test, most of the tests failed with Modal
dialog present error.
When I move back to 2.16, the same scripts are working fine.
This error occurs for a approver button.
Client code for this button is
<input name="btnAppApprove" id="Button2" onclick="javascript:return
ApproveEntity(2,1)" type="button" value="Approve"/>
function ApproveEntity(approvalFlag, approvalType) {
_globalApprovalStatus = approvalFlag;
_globalApprovalType = approvalType;
var adhocApproverId =
document.getElementById(_varhdnAdhocApprover).value;
if (approvalFlag == 2)
_globalComments = '';
//document.getElementById('txtApprovedComments').innerText;
if (approvalFlag == 5) {
_globalComments =
document.getElementById('txtRejectComments').innerText;
if (adhocApproverId > 0) {
if (approvalFlag == 5) {
$find('ModalPopupExtenderBehaviorReject').hide();
document.getElementById(btnHiddenRejectPopup).click();
return false;
}
}
}
if (_globalComments.length <= 1024) {
SendForApprovalFlow();
}
else {
document.getElementById('spnRej').innerText = 'Comments length
should not exceed 1024 characters';
return false;
}
return false;
}
When I started digging the client code to understand why selenium is
detecting the Modal dialog, I have noticed developers have called
$find('ModalPopupExtenderBehaviorReject').hide(); to hide if modal dialog
present.
I feel changes made in the comment #87 is causing the issue.
http://code.google.com/p/selenium/issues/detail?id=284#c87
Hello IE Driver Team,
Can you please look into comment 92, I am not able to upgrade to 2.19.
is there any way to deal with a page that displays an alert through the
JSON remote protocol?
When I try to get a URL of the page with an alert, I'm getting an exception:
11:14:11.332 WARN - Exception thrown
org.openqa.selenium.UnhandledAlertException: Modal dialog present
I'm using the Remote Webdriver 2.19
Same Issue of "org.openqa.selenium.UnhandledAlertException: Modal dialog
present" is happened with me.
IE driver 2.20 - Modal dialog present error for a Java-script alert.
@bharath The UnhandledAlertException is exactly what you should see when
you do not handle a modal dialog produced by the JavaScript alert(),
confirm() or prompt() functions. These are completely separate from
handling of dialogs created by showModalDialog().
@Jim - Thank you,now I got it. I was checking for Page loader icon on the
page when alert was generated. My code is working fine on 2.20.
@Jim..Any update on comment89.
please check issue number 3615:
http://code.google.com/p/selenium/issues/detail?can=2&q=3615&colspec=ID%20Stars%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&id=3615
Hi All,
I inherited a set of tests using WebDriver 2 Java API. We test a lot of
sites that are guarded by a login (javascript popup I believe). The login
dialog blocks WebDriver.get().
The solution I inherited was to spawn another thread where a Robot enters
logon credentials separated by TAB and submitted by ENTER.
This works wonderfully except that sometimes (especially during test
start) the Firefox window does not seem to have focus. The Robot proceeds
to type in whatever application has focus or switching between applications
if the desktop was empty at the start. Does anyone have ideas how I could
ensure that the Firefox window is activated? We have a Jenkins job that
performs mvn test to fire this off. Alternatively, I start tests through
IntelliJ IDE and the problem surfaces in both environments, requiring me to
click the Firefox window (not very automated).
Any help is greatly appreciated!
@vik
have you tried to driver.switchTo().defaultContent() to get focus of the
firefox window?