Python Selenium Chrome Extension Settings Not Loading Using a .crx File

独自空忆成欢 提交于 2020-01-06 09:00:41

问题


I'm working on Python with Selenium.

I figured out how to run Chrome with an extension, the only downside is that the extension has settings and these are always blank when starting an automated Chrome session.

Where or how do I save settings when running a crx file? I tried looking in all the files within the extension folder but I did not find my currents settings in them.. Are they maybe stored in the profile?

Below the code I'm using to open the chrome driver with extension.

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")

I don't want to configure these settings every time I start a sessions. How can I let these settings stick?

Thanks in advance!


回答1:


I already fixed it myself by loading the profile with the chrome driver.

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

Case closed.



来源:https://stackoverflow.com/questions/51288093/python-selenium-chrome-extension-settings-not-loading-using-a-crx-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!