Selenium (WebDriver) Junit 4 在窗口之间切换问题
我正在测试一个 Web 应用程序,该应用程序在单击按钮后很长时间内会创建一个新窗口。顺序是以下
窗口 1:(父窗口)单击按钮创建窗口 2
窗口 2:出现进度窗口,直到服务器上的后台进程返回数据
窗口 3:进度窗口变成第三个窗口(具有不同的句柄)
我想正确等待出现第三个窗口。我知道所有 3 个窗口的“标题”是什么,但是为了从 WebDriver 获取标题,我必须使用以下代码:
while(timeout has not occured...){
for (String handle : _driver.getWindowHandles()) {
String myTitle = driver.switchTo().window(handle).getTitle();
if(3rdWindowTitle.equalsIgnoreCase(myTitle)){
return true;
}
}
}
由于“switchTo”,这将在每次循环时有效地来回切换活动窗口。这会导致 Firefox 窗口来回快速循环,令人讨厌。我需要的是一种获取可用窗口标题的方法,而不必在循环中“切换到”每个窗口等待第三个窗口。有什么想法吗?
我基本上想要一个方法 (waitForWindowByTitle(titleIWant)) ,它将阻塞,直到出现我想要的标题的窗口。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,最好您可以通过检查窗口数量来等待窗口出现。就像:
然后您第一次也是最后一次可以浏览窗口(使用 switchTo)并导航到您想要的窗口。
Well, Better you can wait for your window to appear by checking the number of windows. Like:
then for the first and last time you can browse through the windows (using switchTo) and navigate to the window you want.