How to select an default window or popup in selenium webdriver?



  • I want to select the current window,frame or popup where my browser is pointing. (i.e when i doubleclick or click it opens an popup or window) I want to get through that window or popup using selenium webdriver.So if possible please suggest me how to do it. Thanks in advance.



  • You can use the following code also to handle popup.

     String mainwindow = driver.getWindowHandle();
            for (String popup : driver.getWindowHandles()){
                driver.switchTo().window(popup);
            }
    // Your code on poppup window
            driver.switchTo().window(mainwindow); //Switching to main/parent window
    

    Hope this will help 🙂



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2