python - 如何修复 Selenium WebDriverException : The browser appears to have exited before we could connect?

标签 python selenium selenium-webdriver webdriver

我已经在我的 centos6.4 服务器上安装了 firefox 和 Xvfb 来使用 selenium webdriver。

但是,当我运行代码时,我得到了一个错误。

from selenium import webdriver
browser = webdriver.Firefox()

错误

selenium.common.exceptions.WebDriverException: Message: 
'The browser appears to have exited before we could connect. The output was: None'

我在 stackoverflow 上阅读了一些相关页面,有人建议删除 tmp 文件夹中的所有文件,所以我做到了。但是还是不行。

谁能帮帮我?

提前谢谢你!

编辑

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
    self.binary, timeout),
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
    self.binary.launch_browser(self.profile)
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 64, in launch_browser
    self._wait_until_connectable()
  File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 103, in _wait_until_connectable
    self._get_firefox_output())
selenium.common.exceptions.WebDriverException: Message: 'The browser appears to have exited     before we could connect. The output was: None' 

最佳答案

对于 Google 员工,这个答案对我不起作用,我不得不使用 this answer反而。我正在使用 AWS Ubuntu。

基本上,我需要先安装 Xvfb,然后再安装 pyvirtualdisplay:

sudo apt-get install xvfb
sudo pip install pyvirtualdisplay

一旦我这样做了,这个 python 代码就可以工作了:

#!/usr/bin/env python

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(1024, 768))
display.start()

browser = webdriver.Firefox()
browser.get('http://www.ubuntu.com/')
print browser.page_source

browser.close()
display.stop()

感谢@That1Guy 的第一个回答

关于python - 如何修复 Selenium WebDriverException : The browser appears to have exited before we could connect?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26070834/

相关文章:

google-chrome - 如何停止 Chrome 的选择证书窗口?

python - 将单个整数输入转换为python中的列表

java - 使用 Selenium WebDriver for Firefox 下载 pdf

java - 我如何在 testNG 中使用 IAnnotationTransformer?

java - 如何使用 Selenium WebDriver 删除文本字段中的默认值并输入新值

java - 如何选择最佳的自动化工具与selenium的组合

python - Selenium Python 无法定位元素

python - 更新颜色条边界而不删除前一个颜色条边界

python - 如何在 Pandas 数据框中将其分开?

python - python中 "bound"环境变量的安全方法是什么?