question

RJRD-7070 avatar image
0 Votes"
RJRD-7070 asked ZoebPatrawala-1964 answered

Selenium switch to new window is not working in Edge browser

When clicking on a button that opens a new window in the edge using selenium, the switch is not happening using the selenium switch to window command.

driver.switchTo().window(newWindow)

On click the new window opens as a new tab but the control comes back to the parent window and while trying to switch to the new window using the handle, it throws the exception:

Inside catch block org.openqa.selenium.InvalidArgumentException: invalid argument: 'handle' must be a string (Session info: MicrosoftEdge=87.0.664.41) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53' System info: host: '199-7-164-187', ip: '199.7.164.187', os.name: 'windows', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_181' Driver info: driver.version: unknown Command duration or timeout: 0 milliseconds



ms-edge
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YuZhou-MSFT avatar image
1 Vote"
YuZhou-MSFT answered ZoebPatrawala-1964 commented

Hi @RJRD-7070

I suggest that you use Selenium 4 alpha version which can be downloaded in this page. You also need to use the same version of Edge WebDriver as your Edge browser which can be downloaded in this page.

I use Selenium 4.0.0-alpha05 and the code below, it can work well:

 System.setProperty("webdriver.edge.driver", "your_path_to_edge_webdriver\\msedgedriver.exe");      
 WebDriver driver = new EdgeDriver(); 
 driver.get("https://www.somesite.com");
 // Store the current window handle
 String winHandleBefore = driver.getWindowHandle();
 // Perform the click operation that opens new window
     
 // Switch to new window opened
 for(String winHandle : driver.getWindowHandles()){
       driver.switchTo().window(winHandle);
 }
 // Perform some actions on new window
    
 // Switch back to the first window
 driver.switchTo().window(winHandleBefore);

Note: Please change the path and url in the code to your owns.


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Regards,
Yu Zhou



· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The code u shared is the one I have been using and that throws the exception "org.openqa.selenium.InvalidArgumentException: invalid argument: 'handle' must be a string (Session info: MicrosoftEdge=87.0.664.41) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53' System info: host: '199-7-164-187', ip: '199.7.164.187', os.name: 'windows', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_181' Driver info: driver.version: unknown Command duration or timeout: 0 milliseconds"

0 Votes 0 ·

Hi @RJRD-7070

Which version of Selenium are you using? I guess you're using Selenium 3.141.59 because in your error message it shows Build info: version: '3.141.59'.

Please use Selenium 4.0.0-alpha05 or higher version as I mentioned in the answer.


0 Votes 0 ·

@YuZhou-MSFT : I have same issue when testing a web app in chromium edge using IE mode. When a new window is opened, driver.WindowHandles.Count is 0 always. I even tried with latest Selenium 4 beta.

Once login button is clicked, original login window is closed and home page window is displayed. Same works in IE 11.

1 Vote 1 ·
Show more comments
ZoebPatrawala-1964 avatar image
0 Votes"
ZoebPatrawala-1964 answered

I have the similar issue , running my scripts on selenium 3.1410 and using edge chromium browser.
I click on a button and a new page opens , on this new page an alert pop up comes which is no getting identified and scripts are failing

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.