Reputation: 469
When running WebDriver (Ruby) using Chrome, what are the specific command-line switches or desired_capabilities
to disable Chrome's built-in PDF viewer.
In other words, how does one programmatically configure Chrome to download PDF files rather than open using its internal PDF-viewer plugin?
Upvotes: 1
Views: 2119
Reputation: 56
Updated answer: Chrome 61 : Ruby 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
Upvotes: 3
Reputation: 469
Based on the following resource provided Save PDF instead of opening in Selenium, I found this worked as desired
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
There must be no trailing slash in the directory path
Upvotes: 2