python - Selenium firefox 浏览器无法在使用 Python 的 centos 6.0 上运行

标签 python selenium selenium-webdriver

如何让 Selenium 在 Centos 6.0 上工作?我收到以下错误。我在 python 2.6 上使用 selenium 2.31.0

yum install ImageMagick ImageMagick-perl  xorg-x11-server-Xephyr Xvfb firefox
sudo yum -y install python-imaging
sudo easy_install pyvirtualdisplay
sudo easy_install selenium

from pyvirtualdisplay import Display
from selenium import webdriver
import time
import argparse
import os
display = Display(visible=0, size=(800, 600))
display.start()
browser = webdriver.Firefox()


Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/lib/python2.6/site-packages/selenium-2.31.0-py2.6.egg/selenium/webdriver/firefox/webdriver.py", line 58, in __init__
   self.binary, timeout),
 File "/usr/lib/python2.6/site-packages/selenium-2.31.0-py2.6.egg/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
   self.binary.launch_browser(self.profile)
 File "/usr/lib/python2.6/site-packages/selenium-2.31.0-py2.6.egg/selenium/webdriver/firefox/firefox_binary.py", line 48, in launch_browser
   self._wait_until_connectable()
 File "/usr/lib/python2.6/site-packages/selenium-2.31.0-py2.6.egg/selenium/webdriver/firefox/firefox_binary.py", line 95, in _wait_until_connectable
   self.profile.path, self._get_firefox_output()))
selenium.common.exceptions.WebDriverException: Message: 'Can\'t load the profile. Profile Dir: /tmp/tmpUYQhu2 Firefox output: Xlib:  extension "RANDR" missing on display ":1170.0".
*** LOG addons.xpi: startup
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: /home/efuadmin/.mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/.fedora-langpack-install
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi: No changes found'

最佳答案

对于 python 2.7,selenium 需要安装 pip:

/usr/bin/python2.7 -m pip install --user selenium

在你的 python 2.6 上试试这个。它适用于 Red Hat 6 和 Centos 6。

为了避免调用可执行文件时出现路径问题,您也可以使用此选项:

driver = webdriver.Firefox(executable_path='/bin/geckodriver')

关于python - Selenium firefox 浏览器无法在使用 Python 的 centos 6.0 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15339398/

相关文章:

python - 尝试对无穷远顶点实现外接圆计算时,Bowyer-Watson 三角测量不正确

python - 使用 python(最好是 scipy)插值稀疏网格

python - 如何将提取的 python 请求 URL 变量转换为字符串?

android - 如何使用appium在android中滚动 ListView ?

grails - 从Geb测试访问Spring bean

python Selenium 'click' 命令仅在第一个循环上

java.lang.NoClassDefFoundError : org/openqa/selenium/remote/codec/w3c/W3CHttpCommandCodec

python - 获取嵌套列表中最大值的索引

Python Selenium 如何在点击链接之前等待

java - 如何使用 selenium webdriver 悬停并单击不可见的元素?