Python selenium firefox浏览器启动错误

时间:2016-09-03 09:11:20

标签: python selenium firefox

我正尝试使用以下代码在我的Mac上使用Selenium和Python 3.5启动Firefox(48.0.2):

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://bbc.co.uk')

但是,Firefox无需转到指定的网页即可启动并超时,并显示以下错误消息:

Traceback (most recent call last):
  File "/Users/anthonyperera/Documents/Python/AutomatePython/seleniumexample.py", line 2, in <module>
    browser = webdriver.Firefox()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 108, in _wait_until_connectable
    % (self.profile.path))
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /var/folders/6n/_xgjldp12r59c6gdvgb46nsm0000gn/T/tmpwlxtjbt4 If you specified a log_file in the FirefoxBinary constructor, check it for details.

1 个答案:

答案 0 :(得分:0)

我有同样的问题,我解决了。 Firefox 48+不支持webdriver.Firefox()

我的环境:
MacOS 10.11.6,python 3.5.2,firefox 48.0.2,Django 1.10,selenium 2.53.6

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
caps["binary"] = "/Applications/Firefox.app/Contents/MacOS/firefox-bin"

browser = webdriver.Firefox(capabilities=caps)
browser.get('http://bbc.co.uk')

这就是我的尝试 1.下载geckodriverhttps://github.com/mozilla/geckodriver/releasesv.0.10.0适用于selenium 3(beta)。如果您使用selenium 2.xx,请下载v.0.9.0
2.打开~/.bash_profile。您可以按$ vim ~/.bash_profile进行编辑 3.添加PATH ...... export PATH=$PATH:/path/to/your/.../geckodriver-v0.9.0-mac
4. geckodriver文件夹下的geckodriver-v0.9.0-mac,将其重命名为wires
5.重启shell 6.检查版本
$ wires --version
7.并在代码上方运行!

相关问题