如何使用Selenium 3.0.0 Beta关闭Geckodriver [英] How to close geckodriver with selenium 3.0.0 beta

查看:74
本文介绍了如何使用Selenium 3.0.0 Beta关闭Geckodriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:Win 7,Selenium 3.0.0 beta,FireFox- 49.0.1

Environment: Win 7, Selenium 3.0.0 beta, FireFox- 49.0.1

System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");

WebDriver driver=new FirefoxDriver();    

问题1:

命令:driver.close();((FirefoxDriver) driver).kill();

预期结果:浏览器应关闭.

Expected Result: Browser should close.

实际结果:浏览器没有关闭.

Actual Result: Browser is not closing.

问题2:

命令:driver.quit();

预期结果:浏览器应关闭.

Expected Result: Browser should close.

实际结果:Firefox崩溃了.

Actual Result: Firefox crashed.

得到错误:"FireFox的插件容器已停止工作."

Getting Error: "Plugin container for FireFox has stopped working."

任何建议...

推荐答案

解决方法,直到我们对此进行具体修复为止.尽管有几篇文章表明此问题已在版本50及更高版本中修复,但事实是这并不能始终如一地工作.我已经在Windows 7和驱动程序的两台计算机上安装了最新版本的54.如果使用相同的Java和Selenium版本,Quit可以在一个版本上正常运行,而不能在其他版本上运行.另外,为了在Windows计算机上执行,以下代码将有助于杀死Firefox的所有相关进程.

Workaround until we have concrete fix for this. Although several posts suggest this has been fixed in version 50 and above, the fact is this is not working consistently. I have installed latest version 54 on two machines of Windows 7 and driver. Quit is working fine on one and not on other with same Java and Selenium versions. As an alternative, for executing on Windows machines, the following code would help to kill all related processes of Firefox.

if (browser == "FIREFOX")) {
    try {
        Runtime.getRuntime().exec("taskkill /F /IM geckodriver.exe");
        Runtime.getRuntime().exec("taskkill /F /IM plugin-container.exe");
        Runtime.getRuntime().exec("taskkill /F /IM firefox.exe");
    } catch (IOException e) {
        e.printStackTrace();
    }
} else {
    driver.quit();
}

这篇关于如何使用Selenium 3.0.0 Beta关闭Geckodriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆