我想切換到另一個彈出窗口,但正在給出某種錯誤。我無法弄清楚,爲什麼在不工作的切換窗口,這是給Selenium:無法切換窗口
錯誤代碼是
顯示java.lang.NullPointerException:在進入空值:名稱= 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);
您的問題是從'windowHandle.equals(parentWindowHandle)'到來。我的猜測是'parentWindowHandle'沒有被初始化。 – sircapsalot
你好我初始化parentWindowHandle,但忘了把代碼放在這裏。看看我的代碼,我重新發布.... – imtiyaz