这是通过检查这个特定 Chrome 设置
的元素源来解决的:
经过检查的 HTML:
<div class="checkbox">
<span class="controlled-setting-with-label">
<input id="prompt-for-download" type="checkbox" pref="download.prompt_for_download" metric="Options_AskForSaveLocation">
<span>
<label for="prompt-for-download" i18n-content="downloadLocationAskForSaveLocation">Ask where to save each file before downloading</label>
<span class="bubble-button controlled-setting-indicator" pref="download.prompt_for_download">
<div tabindex="0" role="button"></div></span>
</span>
</span>
</div>
如您所见,input
元素具有pref="download.prompt_for_download"
属性。尤里卡!
现在我们可以设置选项,例如使用 Python:
from selenium import webdriver
options = webdriver.ChromeOptions()
prefs = {'download.prompt_for_download': False}
options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=options)
driver.get('http://stackoverflow.com')