使用Chrome運行WebDriver(Ruby)時,具體的命令行開關或desired_capabilities
將禁用Chrome的內置PDF查看器。Selenium WebDriver(Ruby):如何下載PDF文件?
換句話說,如何以編程方式將Chrome配置爲下載PDF文件而不是使用其內部PDF查看器插件打開?
使用Chrome運行WebDriver(Ruby)時,具體的命令行開關或desired_capabilities
將禁用Chrome的內置PDF查看器。Selenium WebDriver(Ruby):如何下載PDF文件?
換句話說,如何以編程方式將Chrome配置爲下載PDF文件而不是使用其內部PDF查看器插件打開?
基於所提供Save PDF instead of opening in Selenium後續的資源,我發現這個工作根據需要
prefs = {
plugins: {
plugins_disabled: ['Chrome PDF Viewer']
},
download: {
prompt_for_download: false,
directory_upgrade: true,
default_directory: 'desired/download/path'
}
}
browser = Selenium::WebDriver.for :chrome, prefs: prefs
必須有沒有目錄路徑斜槓
更新答案:鉻61:紅寶石2.3: ChromeDriver 2.32.498537
download_prefs = {
prompt_for_download: false,
default_directory: 'desired/download/path'
}
plugin_prefs = {
always_open_pdf_externally: true
}
options = Selenium::WebDriver::Chrome::Options.new
options.add_preference(:download, download_prefs)
options.add_preference(:plugins, plugin_prefs)
driver = Selenium::WebDriver.for :chrome, options: options
爲什麼我會看到'未初始化的常量Selenium :: WebDriver :: Chrome :: Options',即使我有'require'硒-webdriver''? – Noffica
看看這個鏈接http://stackoverflow.com/questions/31871087/save-pd硒替代開啓 – shank087