How can selenium web driver get to know when the new window has opened and then resume its execution

后端 未结 7 570
情深已故
情深已故 2020-12-03 07:05

I am facing an issue in automating a web application using selenium web driver.

The webpage has a button which when clicked opens a new window. When I use the follow

相关标签:
7条回答
  • 2020-12-03 07:42

    You can wait for another window to pop using WebDriverWait. First you have to save current handles of all opened windows:

    private Set<String> windowHandlersSet = driver.getWindowHandles();
    

    Then you click a button to open a new window and wait for it to pop with:

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(driver -> !driver.getWindowHandles().equals(windowHandlersSet));
    

    Which checks if there is a change to current window handles set comparing to saved one. I used this solutnion writing tests under Internet Explorer where it always takes few seconds to open new window.

    0 讨论(0)
提交回复
热议问题