本文介绍了如何使用 Java 在 Selenium WebDriver 中关闭子浏览器窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
切换到新窗口并完成任务后,我想关闭那个新窗口并切换到旧窗口,
After I switch to a new window and complete the task, I want to close that new window and switch to the old window,
所以我在这里写了类似代码:
so here i written like code:
// Perform the click operation that opens new window
String winHandleBefore = driver.getWindowHandle();
// Switch to new window opened
for (String winHandle : driver.getWindowHandles()) {
driver.switchTo().window(winHandle);
}
// Perform the actions on new window
driver.findElement(By.id("edit-name")).clear();
WebElement userName = driver.findElement(By.id("edit-name"));
userName.clear();
try
{
driver.quit();
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("not close");
}
driver.switchTo().window(winHandleBefore);// Again I want to start code this old window
上面我写了代码driver.quit()或driver.close().但我收到错误.谁能帮帮我...?
Above I written code driver.quit() or driver.close(). But I am getting error. Can anybody help me...?
org.openqa.selenium.remote.SessionNotFoundException: 调用 quit() 后无法使用 FirefoxDriver.
org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called.
推荐答案
关闭单个浏览器窗口:
driver.close();
关闭所有(父+子)浏览器窗口并结束整个会话:
To close all (parent+child) browser windows and end the whole session:
driver.quit();
这篇关于如何使用 Java 在 Selenium WebDriver 中关闭子浏览器窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)