Python Selenium 设置多个 Chrome 首选项

标签 python python-2.7 google-chrome selenium selenium-chromedriver

我正在尝试在 Chrome 浏览器中设置多个 Chrome 选项。这是我目前拥有的:

prefs = {"download.default_directory" :  "Download/Path"}
moreprefs = {'safebrowsing.enabled': 'false'}
chromeOptions = webdriver.ChromeOptions() 

chromeOptions.add_experimental_option("prefs", prefs)
chromeOptions.add_experimental_option("prefs", moreprefs)

self.driver = webdriver.Chrome(chrome_options=chromeOptions)

问题是它只考虑 chromeOptions.add_experimental 的 1,而我两者都需要

最佳答案

更新首选项字典。然后设置首选项。

prefs = {"download.default_directory" :  "Download/Path"}
moreprefs = {'safebrowsing.enabled': 'false'}
chromeOptions = webdriver.ChromeOptions() 

prefs.update(moreprefs)
chromeOptions.add_experimental_option("prefs", prefs)

self.driver = webdriver.Chrome(chrome_options=chromeOptions)

关于Python Selenium 设置多个 Chrome 首选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43347044/

相关文章:

google-chrome - 在 Windows 上以全屏模式运行 chrome

javascript - 如何在 Firefox 和 Chrome 中通过网站上的链接打开文件夹?

python - 简单的 flask /gevent 请求没有同时运行

python - 向字符串填充空格或零

python - 发现字符串中的相似性和模式 - Python

python - 将 URL 的标题部分拆分为单独的列 - Python

python - 导入tensorflow时出现numpy版本错误

css - Chrome 在切换标签时隐藏 HTML5 视频

python - 使用来自 geotiff 的 gdal python 读取高程

python - 将数据框列中的日期转换为 MM/DD/YYYY