2016-09-03 69 views
0

我嘗試使用下面的代碼在我的Mac使用Selenium與Python 3.5〜啓動Firefox(48.0.2):Python的硒火狐瀏覽器啓動錯誤

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. 
+0

你是什麼硒的版本?嘗試更新硒。 –

+0

嗨Syed,它是最新版本 - 2.53.6 –

回答

0

我有同樣的問題,我解決了它。 Firefox 48+不支持webdriver.Firefox()

我的環境:
的MacOS 10.11.6,蟒蛇3.5.2,火狐48.0.2,Django的1.10,硒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.添加路徑如..
export PATH=$PATH:/path/to/your/.../geckodriver-v0.9.0-mac
4. geckodrivergeckodriver-v0.9.0-mac下,其重命名爲wires
5.重啓殼
6.檢查版本
$ wires --version
7.並運行上述碼!

相關問題