简体   繁体   English

如何在 selenium 中正确设置 firefox 配置文件?

[英]How to setup firefox profile in selenium correctly?

I have the following code for selenium in python to use my firefox profile, the idea is to save me from login into my frequently visited pages every time, but Selenium still start itself with no 'memory' or 'history' of me being log in to those pages and stayed login.我在 python 中有以下 selenium 代码来使用我的 firefox 配置文件,这个想法是让我免于每次登录到我经常访问的页面,但 Selenium 仍然在没有我登录的“记忆”或“历史”的情况下开始到那些页面并保持登录状态。

What goes wrong please?请问有什么问题?

def create_selenium_FF():
    options = Options()
    profile = webdriver.FirefoxProfile('/Users/Victor 1/Library/Application Support/Firefox/Profiles/z3ay0enb.default')
    driver = webdriver.Firefox(profile)
    driver = webdriver.Firefox()
    return driver

Normally this would do通常这会做

from selenium import webdriver
from selenium.webdriver.firefox.webdriver import FirefoxProfile

profile = FirefoxProfile("C:\\Path\\to\\profile")
driver = webdriver.Firefox(profile)

As some of the options, such as firefox_profile and options.profile are mutually exclusive, precedence is given from how specific the setting is.由于某些选项(例如 firefox_profile 和 options.profile)是互斥的,因此优先级取决于设置的具体程度。 capabilities is the least specific keyword argument, followed by options, followed by firefox_binary and firefox_profile.功能是最不具体的关键字参数,然后是选项,然后是 firefox_binary 和 firefox_profile。

In practice this means that if firefox_profile and options.profile are both set, the selected profile instance will always come from the most specific variable.实际上,这意味着如果 firefox_profile 和 options.profile 都设置了,则所选的配置文件实例将始终来自最具体的变量。 In this case that would be firefox_profile.在这种情况下,这将是 firefox_profile。 This will result in options.profile to be ignored because it is considered a less specific setting than the top-level firefox_profile keyword argument.这将导致 options.profile 被忽略,因为它被认为是比顶级 firefox_profile 关键字参数更不具体的设置。 Similarily, if you had specified a capabilities[“moz:firefoxOptions”][“profile”] Base64 string, this would rank below options.profile.类似地,如果你指定了一个 capabilities[“moz:firefoxOptions”][“profile”] Base64 字符串,它的排名会低于 options.profile。

Can't see your entire code but looks like you have your answer in the above看不到你的整个代码,但看起来你在上面有你的答案

Read it all here:- https://selenium-python.readthedocs.io/api.html?highlight=profile#module-selenium.webdriver.firefox.webdriver在这里阅读所有内容:- https://selenium-python.readthedocs.io/api.html?highlight=profile#module-selenium.webdriver.firefox.webdriver

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

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