簡體   English   中英

使用Firefox驅動程序在Ubuntu LTS上運行無頭Webdriver測試

[英]Running Headless Webdriver Tests on Ubuntu LTS using Firefox driver

我正在使用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"' >> ~/.bashrc在bash配置文件中添加一個指向firefox的鏈接,但這並沒有解決問題。

UPDATE

我能夠成功地將路徑添加到我的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,有沒有人知道解決方案?

根據我的理解,Firefox不是為無頭機制構建的[如果我錯了就糾正我]。 您可以使用PhantomJs來更好地處理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM