【问题标题】:How to setup firefox profile in selenium correctly?如何在 selenium 中正确设置 firefox 配置文件?
【发布时间】:2021-02-13 06:49:40
【问题描述】:

我在 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

【问题讨论】:

    标签: python selenium firefox automation


    【解决方案1】:

    通常会这样

    from selenium import webdriver
    from selenium.webdriver.firefox.webdriver import FirefoxProfile
    
    profile = FirefoxProfile("C:\\Path\\to\\profile")
    driver = webdriver.Firefox(profile)
    

    作为一些选项,比如firefox_profile和options.profile 是互斥的,优先级是从具体的 设置是。能力是最不具体的关键字参数, 然后是选项,然后是 firefox_binary 和 firefox_profile。

    实际上,这意味着如果 firefox_profile 和 options.profile 两者都设置,选定的配置文件实例将始终来自最 具体变量。在这种情况下,这将是 firefox_profile。这 将导致 options.profile 被忽略,因为它被认为是 比顶级 firefox_profile 关键字不太具体的设置 争论。同样,如果您指定了 能力[“moz:firefoxOptions”][“profile”] Base64 字符串,这个 将排在 options.profile 之下。

    看不到你的整个代码,但看起来你在上面有你的答案

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-24
      • 1970-01-01
      • 1970-01-01
      • 2016-08-28
      • 1970-01-01
      • 2016-11-08
      • 2022-01-13
      • 2017-08-07
      相关资源
      最近更新 更多