Selenium Webdriver sessionId 或检查所有浏览器窗口是否已关闭

Selenium Webdriver sessionId 或检查所有浏览器窗口是否已关闭

问题描述:

有没有办法查看所有浏览器窗口是否关闭?我看到,如果您在 WebDriver 上调用 driver.quit() 或 driver.close(),则 sessionId 将变为 null.有没有办法检查?

Is there a way to see if all the browser windows are closed? I see that if you call driver.quit() or driver.close() on the WebDriver, the sessionId becomes null. Is there a way to check that?

我不想调用已关闭或退出的驱动程序,因为它会引发 WebDriverException.所以我想在继续之前检查浏览器的状态.

I don't want to make a call to a closed or quit driver as it throws a WebDriverException. So I want to check to see the state of the browser before continuing on.

只需设置

driver=null; 

每次你退出浏览器然后检查

everytime you quit the browser and than check

if (browser!=null){
  //Attention: this comand is not supported
  //as far as i know ;)
  driver.doSomething();
}

try{


}catch (NullPointerException e)

    e.printStackTrace();
    System.err.print"DAMN";
}

或收到 NullPointerException ;)

or receive a NullPointerException ;)