【问题标题】:Running Headless Webdriver Tests on Ubuntu LTS using Firefox driver使用 Firefox 驱动程序在 Ubuntu LTS 上运行 Headless Webdriver 测试
【发布时间】:2017-06-25 15:07:50
【问题描述】:

我正在使用 selenium 版本 2.53.6 和 firefox 46.0.1 运行 python 2.7.12。我的目标是在 AWS Ubuntu Server 16.04 LTS 上运行无头测试。这就是我设置它的方式。

# install anaconda
cd ~
wget https://repo.continuum.io/archive/Anaconda2-4.2.0-Linux-x86_64.sh
bash Anaconda2-4.2.0-Linux-x86_64.sh
rm Anaconda2-4.2.0-Linux-x86_64.sh
echo export 'PATH="/home/ubuntu/anaconda2/bin:$PATH"' >> ~/.bashrc
source .bashrc
conda update conda

# install firefox version 46.0.1
wget https://ftp.mozilla.org/pub/firefox/releases/46.0.1/linux-x86_64/en-US/firefox-46.0.1.tar.bz2
tar jxf firefox-46.0.1.tar.bz2
rm firefox-46.0.1.tar.bz2

# install pyvirtualdisplay
sudo apt-get install xvfb xserver-xephyr
pip install pyvirtualdisplay

# install selenium version 2.53.6
pip install selenium==2.53.6

当我运行这段代码时

from pyvirtualdisplay import Display
from selenium import webdriver

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

browser = webdriver.Firefox()
driver.get("http://www.python.org")

driver.quit()
display.stop()

我得到这个错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 55, in __init__
self.binary = firefox_binary or capabilities.get("binary",  FirefoxBinary())
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 47, in __init__
self._start_cmd = self._get_firefox_start_cmd()
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 163, in _get_firefox_start_cmd
" Please specify the firefox binary location or install firefox")
RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox

我尝试通过运行echo export 'PATH="$PATH:/home/ubuntu/firefox"' &gt;&gt; ~/.bashrc 在 bash 配置文件中添加指向 Firefox 的链接,但这并没有解决问题。

更新

我能够成功地将路径添加到我的 bash 配置文件。我现在收到此错误

"The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser    appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.

鉴于我已经在使用 pyvirtualdisplay,有人知道解决方案吗?

【问题讨论】:

    标签: python selenium ubuntu firefox


    【解决方案1】:

    据我了解,Firefox 不是为 Headless 机制构建的[如果我错了,请纠正我]。 您可以使用PhantomJs 进行更好的处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-21
      • 1970-01-01
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      • 2019-05-08
      • 2021-09-24
      相关资源
      最近更新 更多