Chromedriver, Selenium - Download Automation
I am using Selenium 2.43.0 with Python 2.7.5. At some point, the test clicks a button that sends information about the form to the server. If the request is successful, the server responds
1) Successful message
2) PDF with information about the form, combined into
I don't need to validate the PDF, my test is just looking for a successful message. However, the PDF is part of the package response from the server, which I, as a tester, cannot change.
Until recently, this was never a problem when using Chromedriver, as Chrome automatically downloaded pdf files to its default folder.
However, a few days ago, one of my test environments started showing up in a separate window with a Print screen for pdfs, which nullified my tests.
I don't need or need this dialogue. How can I suppress this dialog programmatically using the chrome options? (Something that is equivalent to the FireFox options pdfjs.disable
in about:config
).
Here is my current attempt at bypassing a dialog not working ("not working" does not disable or close the pdf print dialog):
dc = DesiredCapabilities.CHROME
dc['loggingPrefs'] = {'browser': 'ALL'}
chrome_profile = webdriver.ChromeOptions()
profile = {"download.default_directory": "C:\\SeleniumTests\\PDF",
"download.prompt_for_download": False,
"download.directory_upgrade": True}
chrome_profile.add_experimental_option("prefs", profile)
chrome_profile.add_argument("--disable-extensions")
chrome_profile.add_argument("--disable-print-preview")
self.driver = webdriver.Chrome(executable_path="C:\\SeleniumTests\\chromedriver.exe",
chrome_options=chrome_profile,
service_args=["--log-path=C:\\SeleniumTests\\chromedriver.log"],
desired_capabilities=dc)
All component versions are the same in both test environments:
Selenium 2.43.0, Python 2.7.5, Chromedriver 2.12, Chrome (browser) 38.0.02125.122
source to share
I had to dig into the source code on this one - I couldn't find any docs listing the full set of Chrome user settings.
Key "plugins.plugins_disabled": ["Chrome PDF Viewer"]}
FULL CODE:
dc = DesiredCapabilities.CHROME
dc['loggingPrefs'] = {'browser': 'ALL'}
chrome_profile = webdriver.ChromeOptions()
profile = {"download.default_directory": "C:\\SeleniumTests\\PDF",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"plugins.plugins_disabled": ["Chrome PDF Viewer"]}
chrome_profile.add_experimental_option("prefs", profile)
#Helpful command line switches
# http://peter.sh/experiments/chromium-command-line-switches/
chrome_profile.add_argument("--disable-extensions")
self.driver = webdriver.Chrome(executable_path="C:\\SeleniumTests\\chromedriver.exe",
chrome_options=chrome_profile,
service_args=["--log-path=C:\\SeleniumTests\\chromedriver.log"],
desired_capabilities=dc)
Interestingly, the team team chrome_profile.add_argument("--disable-plugins")
did not solve this problem. But I prefer a more surgical approach.
source to share