Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Support for window.showModalDialog #284

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

Support for window.showModalDialog #284

lukeis opened this issue Mar 2, 2016 · 129 comments

Comments

@lukeis
Copy link
Member

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 4582 has been merged into this issue.

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

@lukeis
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

lukeis commented Mar 2, 2016

Strange!! No response!!

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

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 4452 has been merged into this issue.

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

@lukeis
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 5748 has been merged into this issue.

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

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 5748 has been merged into this issue.

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

@lukeis
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 7667 has been merged into this issue.

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

@lukeis
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

lukeis commented Mar 2, 2016

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

  • Labels added: Restrict-AddIssueComment-Commit

@SeleniumHQ SeleniumHQ 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.
Projects
None yet
Development

No branches or pull requests

1 participant