[英]Python selenium firefox browser launch error
I am trying to launch Firefox (48.0.2) using Selenium with Python 3.5 on my mac using the following code: 我正在尝试使用以下代码在我的Mac上使用Selenium和Python 3.5启动Firefox(48.0.2):
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://bbc.co.uk')
However, Firefox launches without going to the specified webpage and times out with the following error message: 但是,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.
I had the same issue and I solved it. 我有同样的问题,我解决了。 Firefox 48+ doesn't support
webdriver.Firefox()
. Firefox 48+不支持
webdriver.Firefox()
。
My environment: 我的环境:
MacOS 10.11.6, python 3.5.2, firefox 48.0.2, Django 1.10, selenium 2.53.6 MacOS 10.11.6,python 3.5.2,firefox 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')
This is what I was trying 这就是我正在尝试的
1. download geckodriver
. 1.下载
geckodriver
。 https://github.com/mozilla/geckodriver/releases . https://github.com/mozilla/geckodriver/releases 。
v.0.10.0
is for selenium 3(beta)
. v.0.10.0
适用于selenium 3(beta)
。 if you use selenium 2.xx
, download v.0.9.0
如果您使用
selenium 2.xx
,请下载v.0.9.0
2. open ~/.bash_profile
. 2.打开
~/.bash_profile
。 you can edit it by $ vim ~/.bash_profile
. 您可以通过
$ vim ~/.bash_profile
对其进行编辑。
3. add PATH like.. 3.添加PATH之类的..
export PATH=$PATH:/path/to/your/.../geckodriver-v0.9.0-mac
4. geckodriver
under the folder geckodriver-v0.9.0-mac
, rename it to wires
4.
geckodriver
文件夹下geckodriver-v0.9.0-mac
,其重命名为wires
5. restart shell 5.重启shell
6. check the version 6.检查版本
$ wires --version
7. and run above the code! 7.并运行上面的代码!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.