Steps to reproduce
I am writing tests and there are some places that when I click on a button, a new browser (as in New modal window) will be opened. I have already handled them by using
webDriver.switchTo().window(windowHandle), and it works fine on 3 browsers Chrome, Firefox and Internet Explorer 11.
Now I am trying to run these tests on Microsoft Edge. It works as expected, except when it comes to modal windows:
When I let the tests run to the point I click on the button, I saw
that the Modal Window was opened and disappeard in a blink, it was
not in the background as well.
When I debug the tests to the click() action, then the Modal window
was opened and stayed there after the click(), and the tests could
I thought it was fast, so I added a wait after click() like this:
webDriver.findElement(By.name("firstReport")).click(); Thread.sleep(5000); // wait 5 seconds
but the Modal window always disappeared right after the click() action. I also tried with:
But the same result. The Modal Window only stays when I choose
Debug instead of
My enviroment: IntelliJ with
MicrosoftWebDriver.exe Version: 5.16299 for
Win10 OS Build Release 16299 (from Microsoft WebDriver)
EXPECTED RESULT: Modal Window will be opened and stayed
ACTUAL RESULT: Modal Window was opened and disappeared/closed immediately
Comments and activity
This is HTML of the button:
- Microsoft Edge Team
Changed Assigned To to “Steven K.”
Will you provide a repro for this?
I am wondering how you are displaying the modal. Does your call to sendReportAction() modify the display property? A simplified repro would really help.
I am attaching my modal testing. Below are the step to execute my no repro.
// assumes maven installed and in path: choco install maven -y
// assumes nodejs installed and in path: choco install nodejs.install -y
// assumes java 1.8.x installed and in path: choco install jdk8 -y
// assumes gitbash installed: choco install git -y
- install the Microsoft webdriver.exe and make sure it is in your path
// For insider releases - use this command in an Administrator PowerShell
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
- unzip public-repro.zip
- Run Express server
open gitbash to serverA folder
optional: verify webserver by opening URL:http://127.0.0.1:3000/edgetest.html
- run webDriver from command line
open gitbash to webdriverjavaextensionapp folder containing the pom.xml file
mvn clean compile package
java -jar target/AppFatJar-1.0-SNAPSHOT-spring-boot.jar
Thank you for looking into the issue. About your question if action sendReportAction() modifies the display property, I am attaching the JS of this action.
About the repro, I also provide the test code, becasue it is the start point of the test, so just create EdgeDriver and click on this button. I hope it could help, and sorry if I can’t provide more information.
Were you able to run the repro I provided?
If you provide a complete repro, I can test it. However, my repro is showing that modals are handled properly for the case I created.
sorry for a late reply. Unfortunately, I was not able to run your repro. My env is Linux, so I use RemoteWebDriver to a Selenium Node which I don’t have access to.
But I was able to run the Express Server and have a look at http://127.0.0.1:3000/edgetest.html , I see that your Modal is still attached to browser. In my case, when I click on that button, it opens a new browser/window, that’s where I guess windleHandle is lost ?!
I was asking my dev team to pack a reasonable repro which introduces this modal window thingy, but no result. Sorry for that.
Thanks and regards,
I understand the issue now. You will have to use the driver.SwitchTo().window() method to first get access to the new window. Here are some examples of how to do that.
Let me know if using the switchTo().window(handle) does not solve the issue.
Yes, I have used the method driver.SwitchTo().window() already, and it works really well with IE11, Chrome and FF in this regard.
But the issue with Edge is that, when I let the tests run, this new window/browser is opened and closed immediately, it is completely gone after action click(). That’s why when it reaches to driver.SwitchTo().window(), there is no window to switch!
When I run the tests with Debug mode, steps by steps, this new window/browser is opened and displayed, therefore I can switchTo(), and the tests carry on.
However, I just had a workaround for this. Before action click() to open this new window, I put a Thread.sleep() 5 seconds and it somehow works! Maybe Edge can take it into account for an improvement.
Thanks for your time looking into this issue.
I am attaching 2 files:
video file without_sleep_before_action_click.mp4: you can see in this video, the click() action was executed, and in a blink, the new window is gone.
image with_sleep_before_action_click.png: if I put a Thread.Sleep() 5 seconds before click(), then the new window is displayed, like this: