开发者

Selenium (WebDriver) Junit 4 switching between windows issue

I am testing a web application that creates a new window long after a button is clicked. The sequence is the following

window 1: (parent window) click button to create window 2

window 2: progress window appears until background process on server returns data

window 3: progress window turns into 3rd window (with different handle)

I want to properly wait for the 3rd window to appear. I know what the 'title' of all 3 windows will be however in order to get the titles from WebDriver I have to use the following code:

while(timeout has not occured...){ 
    for (String handle : _driver.getWindowHandles()) {
       String myTitle = driver.switchTo().window(handle).getTitle();
       if(3rdWindowTitle.equalsIgnoreCase(myTitle)){
           return true;
       }
    }
}

This will effectively switch the active window back and forth every time it loops because of the 'switchTo'. This causes the firefox windows to cycle back and forth really quickly and is obnoxious. What I need is a way to get the title's of the windows that are available without having to 'switchTo' each window in a loop waiting for the 3rd window. Any ideas?

I basically want a method (waitForWindowByTitle(开发者_开发技巧titleIWant)) which will block until the window with the title I want appears.


Well, Better you can wait for your window to appear by checking the number of windows. Like:

for(int i=0; i<noOfTrials;i++){
        noOfWindows = driver.getWindowHandles().size();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        if(noOfWindows>currentNoOfWindows){
        break;
        }
    }

}

then for the first and last time you can browse through the windows (using switchTo) and navigate to the window you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜