WebDriver.getWindowHandle() method

后端 未结 5 1229
春和景丽
春和景丽 2020-12-18 07:49

I\'m new to Selenium learning. WebDriver.getWindowHandle() documentation is not very clear to me and the example is not working as given in the book, so I thought of confirm

5条回答
  •  [愿得一人]
    2020-12-18 07:59

    If the link opens a new window you should have a new window handle in the WebDriver. You can loop current window handles with getWindowHandles.

    See this example from http://www.thoughtworks.com/products/docs/twist/13.3/help/how_do_i_handle_popup_in_selenium2.html

      String parentWindowHandle = browser.getWindowHandle(); // save the current window handle.
      WebDriver popup = null;
      Iterator windowIterator = browser.getWindowHandles();
      while(windowIterator.hasNext()) { 
        String windowHandle = windowIterator.next(); 
        popup = browser.switchTo().window(windowHandle);
        if (popup.getTitle().equals("Google") {
          break;
        }
      }
    

提交回复
热议问题