首页 > 解决方案 > Python Selenium Chrome 扩展设置未使用 .crx 文件加载

问题描述

我正在使用 Selenium 开发 Python。

我想出了如何使用扩展程序运行 Chrome,唯一的缺点是扩展程序具有设置,并且在启动自动 Chrome 会话时这些设置始终为空白。

运行 crx 文件时在哪里或如何保存设置?我尝试查看扩展文件夹中的所有文件,但我没有在其中找到我的当前设置。它们可能存储在配置文件中吗?

在我用来打开带有扩展名的 chrome 驱动程序的代码下方。

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


executable_path = "/webdrivers"
os.environ["webdriver.chrome.driver"] = executable_path

chrome_options = Options()
chrome_options.add_extension('/webdrivers/extension_3_1_0_0.crx')

driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("http://stackoverflow.com")

我不想在每次开始会话时都配置这些设置。我怎样才能让这些设置保持不变?

提前致谢!

标签: pythongoogle-chromeseleniumgoogle-chrome-extension

解决方案


我已经通过使用 chrome 驱动程序加载配置文件自己修复了它。

options = Options()
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=DIRECTORYTOPROFILEFOLDERWITHINAPPDATA")

结案。


推荐阅读