我正在尝试通过查看 here 安装 python-selenium 绑定(bind)
当我尝试导入以下命令时,它显示以下错误
from selenium.firefox.webdriver import WebDriver
结果:
from selenium.firefox.webdriver import WebDriver
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named firefox.webdriver
我进行了很多搜索来解决这个问题,但是我没有找到正确的示例来执行此操作,任何人都可以为我提供一种方法和示例,说明如何安装 python selenium 绑定(bind)以及为什么返回上述错误。
提前致谢............
已编辑: 我根据下面的答案编辑我的代码,并尝试了以下操作,我得到了下面的
>>> from selenium import webdriver
>>> driver = webdriver.Firefox()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/selenium-2.21.3-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 51, in __init__
self.binary, timeout),
File "/usr/lib/python2.7/site-packages/selenium-2.21.3-py2.7.egg/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/lib/python2.7/site-packages/selenium-2.21.3-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 44, in launch_browser
self._wait_until_connectable()
File "/usr/lib/python2.7/site-packages/selenium-2.21.3-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 81, 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: *** LOG addons.xpi: startup\n*** LOG addons.xpi: checkForChanges\n*** LOG addons.xpi: Opening database\n*** LOG addons.xpi: No changes found\nFailed to dlopen /usr/lib/libX11.so.6\ndlerror says: /usr/lib/libX11.so.6: wrong ELF class: ELFCLASS32\n'
并且还说 firefox 1.0 中存在一些崩溃......
最佳答案
正如该页面所述,他们已经重新组织了包裹。使用我在此处发布的第二个代码 list 。
One advantage of using trunk as of writing, is the reorganization of the package. Previously, to initialize a browser you had to perform,
from selenium.firefox.webdriver import WebDriver
driver = WebDriver()
This has been changed, so now all that is required is:
from selenium import webdriver
driver = webdriver.Firefox()
编辑(新错误):
您是否在没有 X 显示的 Linux 服务器上运行此程序? Firefox 需要显示器来呈现自身。看看PyVirtualDisplay用于运行“ headless ”(没有 X)。
关于python - 在 fedora 上安装 python selenium 绑定(bind)时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11152957/