似乎加载配置文件仍然失败,即使我指定配置文件的路径位置,它似乎从不同的路径加载(根据追溯)。我在这里错过了什么吗?
CODE
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
profile = FirefoxProfile('/Users/path/Library/Application Support/Firefox/Profiles/9s60syvx.default')
browser = webdriver.Firefox(firefox_profile=profile)
<snip>
TRACKBACK
File "/Users/path/Python/Projects/test/login.py", line 12, in <module>
browser = webdriver.Firefox(firefox_profile=profile)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 80, in __init__
self.binary, timeout)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "/usr/local/lib/python2.7/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/dy/yl4zdm8n5j184hhfq_2j3bdh0000gn/T/tmpY3UPuy/webdriver-py-profilecopy If you specified a log_file in the FirefoxBinary constructor, check it for details.
Firefox版本= 48.0.2
selenium Version = 2.53.6
操作系统版本= OSX 10.11.6
答案 0 :(得分:0)
最简单的方法是将geckodriver
二进制文件移动到PATH
中已有的目录:
mv geckodriver /usr/local/bin
如果您想将其放在其他位置,请注意PATH
必须指向包含geckodriver
的目录,而不是二进制本身。要将自定义目录添加到PATH
,您应该在代码中执行此操作,因为您可能不希望在系统范围内使用它。
os.environ["PATH"] += os.pathsep + 'path/to/dir/containing/geckodriver/'
在那之后,做你想要的通常的东西。
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = '/usr/bin/firefox'
profile = FirefoxProfile('/path/to/your/profile')
browser = webdriver.Firefox(capabilities=firefox_capabilities
firefox_profile=profile)