Selenium switch to new window is not working in Edge browser

RJ RD 21 Reputation points
2020-12-01T14:38:10.46+00:00

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

Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,105 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Yu Zhou-MSFT 11,956 Reputation points Microsoft Vendor
    2020-12-02T06:16:38.45+00:00

    Hi @RJ RD

    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

    1 person found this answer helpful.

  2. Zoeb Patrawala 1 Reputation point
    2022-01-04T10:29:09.617+00:00

    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

    0 comments No comments