java如何关闭一个浏览器网页代码,如何使用Java关闭Selenium WebDriver中的子浏览器窗口...

Here I am getting some problem since a long time. And I couldn't figure out that,can anybody would like to help me? ... when i am going to switch new window ,after complete the task of new windows. I want to close that new window.and switch 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

Above I written code driver.quit() or driver.close(). But I am getting error. Can anybody help me...?

org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called.

解决方案

To close a single browser window:

driver.close();

To close all (parent+child) browser windows and end the whole session:

driver.quit();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值