如何在 chromedriver 嵌入的 chromium 中设置用户数据目录?

How do I set user data directory in chromium-embedded with chromedriver?

我正在尝试将 CEF 用于 chrome 配置文件之类的功能。经过一番谷歌搜索后,我发现 CEF 通过 CefSettings.cache_path 和 --cache-path.

支持类似的功能

但我不知道如何通过 chrome 驱动程序设置此功能。

您可以使用 chromeOptions 将缓存路径作为参数传递。

请查看以下示例代码:

from selenium  import webdriver
from selenium.webdriver.chrome.options import Options
chromeOptions = Options()

chromeOptions.add_argument("--cache-path=C:\CEF\c_path")
chromeOptions.binary_location = r"C:\cef_binary_client\Release\cefclient.exe"

driver = webdriver.Chrome(executable_path=r"C:\Driver\chromedriver_220.exe", chrome_options=chromeOptions)

driver.get("https://google.com")
s = "test" 
driver.find_element_by_name("q").send_keys(s)