在Win 8.1中使用IE11从子窗口切换到父窗口时,Selenium WebDriver挂起或卡住 [英] Selenium WebDriver hungs or gets stuck while switching from child window to parent window using IE11 in Win 8.1

查看:158
本文介绍了在Win 8.1中使用IE11从子窗口切换到父窗口时,Selenium WebDriver挂起或卡住的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Selenium WebDriver-从子窗口切换回父窗口时挂起或卡住.如果在调试模式下手动在父窗口中更改特定页面,则成功从子窗口切换到父窗口.猜测父窗口中的特定页面会阻止窗口切换,因为它希望关闭子窗口.我该如何解决此问题?(将控件带回父窗口以进行进一步验证)(还建议是否有其他方法可用于切换Windows)

Selenium WebDriver- hungs or stucks while switching back from child window to parent window. If I change the specific page in parent window Manually on debug mode,Successfully switch is happening from child to parent window. Guessing that specific page in parent window blocks switching of windows as it expects child window to be closed.How can i overcome this Issue?(To bring back control to parent window for further validation)(Also Suggest if any alternative methods are available to switch windows)

代码:(已使用的正确代码)

Code:(Used Right Code)

String parentWin = browser.getWindowHandle();
Set<String> handles = browser.getWindowHandles();
String winHandle = null;
Iterator<String> itr = handles.iterator();while(itr.hasNext())
{
    winHandle = itr.next();
    if (!winHandle.equals(parentWin)) {
        browser.switchTo().window(winHandle); //Tried Giving Enough delay also
        browser.switchTo().window(parentWin);// It hungs here (Executes at
                                                // the case if change the
                                                // specific page in parent 
                                                // window)
    }

}

推荐答案

问题

根据您的代码试用,您正在执行先打开子窗口的操作.接下来,您尝试将父窗口句柄存储为String parentWin = browser.getWindowHandle();.但是到那时,子窗口已启动,因此子窗口句柄已存储在parentWin中.因此,WebDriver稍后将无法切换到真正的父窗口.

The Issue

As per your code trials, you are performing the action to open the child window first. Next you are trying to store the parent window handle as String parentWin = browser.getWindowHandle();. But by that time the child window is initiated so the child window handle gets stored in parentWin. Hence WebDriver is unable to switch to the real parent window later.

在执行打开子窗口的操作之前,将父窗口的窗口句柄存储在String中.这是工作代码集:

Before you perform the action for opening the child window store the window handle of the parent window in a String. Here is the working set of code:

String parentWin = browser.getWindowHandle();
//perform the action/click which opens a child window
//Now create the Set
Set<String> handles = browser.getWindowHandles();
//Create iterator to traverse
Iterator<String> itr = handles.iterator();
//create a while loop if there are multiple window handles
while(i1.hasNext())
{
  //Store the Child window handle
  String child_window = i1.next();
  //Check if parent window handle not equals child window handle
  if (!parentWin.equalsIgnoreCase(child_window))
  {
    //child window present, so switch to child
    driver.switchTo().window(child_window);
    //Do your work here on child window
    //switch back to parent window
    browser.switchTo().window(parentWin );
  }
}

这篇关于在Win 8.1中使用IE11从子窗口切换到父窗口时,Selenium WebDriver挂起或卡住的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆