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

它给的错误是

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);

最佳答案

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

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


代替

if(!windowHandle.equals(parentWindowHandle)){}

08-05 06:38