gpt4 book ai didi

java - Selenium:没有这样的窗口:目标窗口已关闭

转载 作者:行者123 更新时间:2023-12-02 10:22:43 31 4
gpt4 key购买 nike

我希望我的脚本能够切换窗口。它应该切换到第二个窗口,然后再次切换回第一个窗口,以便我可以继续在当前窗口中进行操作。我找不到为什么第一个窗口已经关闭。

   public void doDetails(){
logger.info("########## Started ##########");

// Store the current window handle
String winHandleBefore = driver.getWindowHandle();
getAllComponents();
mouseOnArrow();
WaitUtils.waitUntilVisiblityOfElement(driver,link,WaitUtils.FIVE_SECONDS);

//Click operation opens another window/tab
link.click();
WaitUtils.waitForSeconds(WaitUtils.FIVE_SECONDS);

//Switching to new window
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
addFilter();
WaitUtils.waitForSeconds(WaitUtils.TEN_SECONDS);
components.clickCustomize();
WaitUtils.waitUntilVisiblityOfElement(driver,components.allCheckboxes,WaitUtils.TWENTY_SECONDS);
components.clickAllChkBoxes();
WaitUtils.waitForSeconds(WaitUtils.ONE_SECOND);
clickAllDetail();
WaitUtils.waitForSeconds(WaitUtils.ONE_SECOND);
components.clickApply();
WaitUtils.waitUntilInvisibilityOf(driver,components.customizeHeader,WaitUtils.TWENTY_SECONDS);
sortByAllowedAmount();
WaitUtils.waitUntilInvisibilityOf(driver,components.loading,WaitUtils.TWENTY_SECONDS);
clickExcel();
WaitUtils.waitForSeconds(WaitUtils.TEN_SECONDS);

//Closing current window
driver.close();

//Switching back to first window
driver.switchTo().window(winHandleBefore);

}

最佳答案

在您的代码中,您必须在切换到新窗口时添加检查。在您的代码中,您位于当前窗口。

   //Switching to new window
for(String winHandle : driver.getWindowHandles()){
if(!(winHandle.equals(winHandleBefore)){
driver.switchTo().window(winHandle);
}
}

这应该适合你。

关于java - Selenium:没有这样的窗口:目标窗口已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54213147/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com