首页 文章

如何修复Selenium WebDriverException:“浏览器似乎已退出”

提问于
浏览
5

当我想使用 FireFox webdriver 时出现此异常

引发WebDriverException“浏览器似乎已退出”WebDriverException:消息:在我们连接之前,浏览器似乎已退出 . 如果在FirefoxBinary构造函数中指定了log_file,请检查它是否有详细信息 .

我读了this question并更新了我的硒,但我已经遇到了同样的问题 .

我的代码:

driver = webdriver.Firefox()
time.sleep(5)
driver.get('http://www.example.com')

UPDATE

我看了this question

现在我有这个错误

OSError: [Errno 20] Not a directory
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x407a690>> ignored

5 回答

  • 4

    如果您在Firefox 47.0上运行Selenium,则需要更新到未在Ubuntu主存储库中发布的Firefox 47.0.1 ..因此您必须添加此PPA:https://launchpad.net/~ubuntu-mozilla- security / archive / ubuntu / ppa

    发行说明:https://www.mozilla.org/en-US/firefox/47.0.1/releasenotes/

    “Selenium WebDriver可能会导致Firefox在启动时崩溃”

    Firefox 48.0发布后,它将包含修复程序 . 我认为Ubuntu已经跳过此更新,因为它影响的用户很少 .

    我可以用FF 47.0和Selenium 2.53确认错误,我也可以确认升级到FF 47.0.1修复了错误 .

  • 0

    这可以通过手动更新firefox 47.0.0到47.0.1来解决

  • 8

    我的selenium脚本遇到了同样的问题 . 我必须确保我使用的是selenium安装文档中描述的正确软件版本,即Pyhton 3.5和Firefox版本45(https://support.mozilla.org/en-US/kb/install-older-version-of-firefox) . 我正在使用硒版本2.9.1虽然从2.53左右阅读可能效果最好 .

    我在评论中注意到您还质疑如何检查Firefox的版本 . 要执行此操作,您可以打开Firefox浏览器,单击菜单按钮并单击弹出菜单底部的问号,最后单击“关于Firefox” . 版本号应该是弹出窗口中的第二行文本 . 可能有其他方法可以这样做,但这对我有用 .

    希望这可以帮助您运行脚本 .

  • 1

    只是对于像我这样浪费时间安装几个firefox版本才能使其工作的人:如果你在没有显示的环境中运行测试(例如SSH到你的流浪盒),就会出现相同的消息错误 .

    sudo apt-get install xvfb
    
    #set display number to :99
    Xvfb :99 -ac &
    export DISPLAY=:99
    

    请记住将其放在.bashrc中,因为它仅在当前会话shell中有效 .

    从:

    Is it possible to run selenium (Firefox) web driver without a GUI?

  • 2

    1.安装最新的Firefox(我的是50.1.0)

    apt-get install firefox
    

    2-从this repo下载最新的geckodriver

    3-解压缩下载的文件

    tar -xvf geckodriver-v0.13.0-linux64.tar.gz
    

    4- mv ./geckodriver /usr/bin

    5- ln -s /usr/bin/geckodriver /usr/local/bin/.

相关问题