1

我正在尝试切换到另一个弹出窗口,但出现了某种错误。我无法弄清楚为什么代码不能用于切换窗口

它给出的错误是

java.lang.NullPointerException:条目中的空值:name=null

这是代码....

String parentWindowHandle = driver.getWindowHandle();
        System.out.println("parentWindowHandle......"+parentWindowHandle);
        //click on "register"

        Actions act = new Actions(driver);
            act.click(driver.findElement(By.id("ctl00_ContentPlaceHolder1_btnRegisterMe")));
        act.perform();

        sleep(26000); 
        String popUpWindowHandle=null;
        Set<String> openWindowsList = driver.getWindowHandles();
        for (String windowHandle : openWindowsList) {
             System.out.println("windowHandle......"+windowHandle);
            if (!windowHandle.equals(parentWindowHandle))
                {popUpWindowHandle = windowHandle;

              break;}
        }                                                
                // Switching control to newly opened window

        driver.switchTo().window(popUpWindowHandle);
4

1 回答 1

0

如果您能够打印窗口句柄,请尝试

if (!windowHandle.equalsIgnoreCase(parentWindowHandle)){
            popUpWindowHandle = windowHandle;
            break;
}

代替

if(!windowHandle.equals(parentWindowHandle)){}
于 2013-10-24T06:39:32.577 回答