Webdriver : How to switch to a specific window?



  • I came across many solutions for switching between windows, one of them is:

    Set allWindows = driver.getWindowHandles();
    for(String currentWindow : allWindows){
       driver.switchTo().window(currentWindow);
    }
    

    But, I am unable to go to a particular window. Can someone tell me how to switch to 3rd window from parent window (using java client library)?



  • The solution I would use is the WebDriver's driver.switchTo().frame() method but avoiding the index number.

    You can select the window you want using;

    1. A number. (0 based index normally but NOT always with IE)
    2. A name or ID.
    3. A previously found WebElement.

    An example:

    driver.switchTo().frame(driver.findElement(By.id("Head1")));
    


Suggested Topics

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