How to start Firefox with with specific profile Selenium Python geckodriver

时间:2017-08-05 10:46:58

标签: python selenium geckodriver

Here is my code:

profile = webdriver.FirefoxProfile('C:\\Users\\Administrator\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\kvycjolb.Prdel')
driver = webdriver.Firefox(profile)

Im not getting any error and firefox starts, but it just does not load with this profile: I have tried changing / to // etc.. but no luck.

This also does not work:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe")
profile = FirefoxProfile("C:\\Users\\Administrator\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\kvycjolb.Prdel")
driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, executable_path="C:\\aprog\\geckodriver.exe")
driver.get('https://google.com')

Im getting error:

C:\aprog>testff
Traceback (most recent call last):
  File "C:\aprog\testff.py", line 7, in <module>
    driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, e
xecutable_path="C:\\aprog\\geckodriver.exe")
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py",
line 152, in __init__
    keep_alive=True)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 98, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 188, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 256, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py"
, line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Unable to find a matchin
g set of capabilities

3 个答案:

答案 0 :(得分:1)

要通过Selenium 3.4.3geckodriver v0.18.0Mozila Firefox 53.0Python 3.6启动具有特定Firefox配置文件的Mozilla Firefox,您需要创建一个单独的Firefox Profile到{ {1}}根据文档here。我创建了一个名为 Firefox Profile Manager Firefox Profile。此配置文件存储在“C:\ Users \ AtechM_03 \ AppData \ Roaming \ Mozilla \ Firefox \ Profiles”子目录中,名称为 debanjan 。因此,在启动w8iy627a.debanjan实例时,我们必须传递名为 WebDriver Firefox Profile的绝对路径,如下所示:

w8iy627a.debanjan

如果这回答你的问题,请告诉我。

答案 1 :(得分:0)

Always use double backslashes in the path (for Windows paths at least):

profile = webdriver.FirefoxProfile('C:\\Users\\Administrator\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\kvycjolb.Prree')

In your code, you use both backslashes and forward slashes.

答案 2 :(得分:0)

我认为官方答案可以在documentation中找到。

当前是:

# Custom profile folder to keep the minidump files
profile = tempfile.mkdtemp(".selenium")
print("*** Using profile: {}".format(profile))

# Use the above folder as custom profile
opts = Options()
opts.add_argument("-profile")
opts.add_argument(profile)
opts.binary = "/Applications/Firefox.app/Contents/MacOS/firefox"

driver = webdriver.Firefox(options=opts,
    # hard-code the Marionette port so geckodriver can connect
    service_args=["--marionette-port", "2828"])