【问题标题】:stop selenium from creating new firefox profile every launch阻止 selenium 在每次启动时创建新的 Firefox 配置文件
【发布时间】:2020-07-25 18:23:05
【问题描述】:

我正在使用seleniumyaml 来自朋友的代码,每次启动都会创建一个新的 Firefox 配置文件,我想使用我自己的配置文件,而不是新的配置文件

这是代码的一部分,我一直在搜索并尝试一切来解决问题,但我不知道该怎么做:

from selenium.webdriver.firefox.options import Options
from selenium import webdriver
import yaml
import os

with open("assets/config.yaml", "r") as config:
    config = yaml.safe_load(config)

options = Options()
if config.get("settings").get("headless"):
    options.headless = True

    profile = webdriver.Firefox(executable_path=config.get("settings").get("firefox"), service_log_path=os.path.devnull if not config.get("settings").get("log") else config.get("settings").get("log"), options=options)

这是来自 config.yaml 的代码:

settings:
  headless: False
  firefox: assets/geckodriver.exe
  log: null

【问题讨论】:

  • 你能发帖config.yaml吗?
  • 我编辑了帖子并添加了它
  • 我刚刚运行了你的代码,但什么也没发生...
  • 我发布了与firefox profie相关的部分代码,而不是完整的脚本代码
  • 完整代码运行良好,我唯一的问题是我想使用自己的 Firefox 配置文件,而不是每次启动都使用新配置文件

标签: python selenium yaml firefox-profile


【解决方案1】:

我已经将它与 Java 一起使用,所以通常你可以按照以下步骤操作:

  1. 使用Firefox.exe -p 创建配置文件,该配置文件在“C:\Users\xUser\AppData\Roaming\Mozilla\Firefox\Profiles”中创建为xyz.Selenium
  2. Python 绑定中应该有一个FirefoxProfile 类。
  3. 将该文件传递给该类并使用驱动程序对象中的配置文件对象。

【讨论】:

猜你喜欢
  • 2016-01-28
  • 2015-01-11
  • 2021-08-06
  • 1970-01-01
  • 2020-11-19
  • 2021-08-20
  • 1970-01-01
  • 1970-01-01
  • 2012-03-07
相关资源
最近更新 更多