I am trying to change settings for Chrome driver so that it allows me to do both of the following:
Although both the solutions work phenomenally in isolation, my attempts to combine them have failed disastrously. Below are the two isolated part solutions. Appreciate any help here.
Code 1:
### This version save pdf automatically but has automation popup.
from selenium import webdriver
import time
timestr = time.strftime("%Y%m")
options = webdriver.ChromeOptions()
prefs = {
"download.default_directory": r"C:\temp\\"+timestr,
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"plugins.always_open_pdf_externally": True
}
options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(executable_path="C://temp//chromedriver.exe",options=options)
driver.get("https://www.tutorialspoint.com/selenium/selenium_tutorial.pdf")
Code 2:
### This version has no automation popup but doesn't save pdf automatically.
from selenium import webdriver
import time
timestr = time.strftime("%Y%m")
capabilities = {
'browserName': 'chrome',
'chromeOptions': {
'useAutomationExtension': False,
'forceDevToolsScreenshot': True,
'args': ['--start-maximized', '--disable-infobars']
}
}
driver = webdriver.Chrome(executable_path="C://temp//chromedriver.exe",desired_capabilities=capabilities)
driver.get("https://www.tutorialspoint.com/selenium/selenium_tutorial.pdf")
You can convert options to desired capabilities and pass it to the desired_capabilities
parameter during creation of driver:
capabilities.update(options.to_capabilities())
Hope it helps you!