简体   繁体   English

Python selenium web驱动程序错误

[英]Python selenium web driver error

It seems that loading the profile keeps failing even though I am specifying the path location of the profile it seems to be loading from a different path (according to the traceback). 似乎加载配置文件仍然失败,即使我指定配置文件的路径位置,它似乎从不同的路径加载(根据追溯)。 Am I missing something here? 我在这里错过了什么吗?

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 Version = 48.0.2 Firefox版本= 48.0.2

selenium Version = 2.53.6 硒版本= 2.53.6

OS Version = OSX 10.11.6 操作系统版本= OSX 10.11.6

The simplest way is to move the geckodriver binary to the directory you already have in the PATH : 最简单的方法是将geckodriver二进制文件移动到PATH已有的目录:

mv geckodriver /usr/local/bin

If you want to have it at a different location, please note that the PATH has to point to the directory that contains the geckodriver and not to the binary itself. 如果您想将它放在不同的位置,请注意PATH必须指向包含geckodriver的目录,而不是二进制本身。 To add the the custom directory to the PATH you should do it in the code because you probably don't want to have it system wide. 要将自定义目录添加到PATH您应该在代码中执行此操作,因为您可能不希望在系统范围内使用它。

os.environ["PATH"] += os.pathsep + 'path/to/dir/containing/geckodriver/'

After that, do the usual stuff you want. 在那之后,做你想要的通常的东西。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM