Python Selenium Set Multiple Chrome Preference

荒凉一梦 提交于 2021-01-28 06:25:25

问题


I am trying to set multiple chrome options in my chrome browser. This is what I currently have:

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)

The probblem is it only takes in to account the 1 of the chromeOptions.add_experimental and I need both


回答1:


update the prefs dictionary. and then set the preference.

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)



回答2:


try this:

prefs = {"download.default_directory": "your_dir", 'safebrowsing.enabled': True}

chromeOptions.add_experimental_option("prefs", prefs)


来源:https://stackoverflow.com/questions/43347044/python-selenium-set-multiple-chrome-preference

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