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

2024-06-07 07:39:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python中为selenium编写了以下代码,以使用我的firefox配置文件,其目的是避免我每次登录频繁访问的页面,但selenium在开始时仍然没有我登录这些页面并保持登录状态的“内存”或“历史记录”

请问出了什么问题

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

Tags: 内存代码目的历史记录状态def配置文件driver
1条回答
网友
1楼 · 发布于 2024-06-07 07:39:09

通常这样就可以了

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. capabilities is the least specific keyword argument, followed by options, followed by firefox_binary and 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. In this case that would be 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. Similarily, if you had specified a capabilities[“moz:firefoxOptions”][“profile”] Base64 string, this would rank below options.profile.

看不到您的全部代码,但看起来您的答案在上面

请在此处通读:-https://selenium-python.readthedocs.io/api.html?highlight=profile#module-selenium.webdriver.firefox.webdriver

相关问题 更多 >

    热门问题