I'm trying to save pages as PDF, but cannot set "id" to "Save as PDF"(chrome driver's version is 98). There are many similar examples on stack overflow, but that solutions didn't work. I can set download.dfrault_directory, it doesn't matter, only "Save as PDF" bothering me. this is window what i want to control or apply settings I already reffered this -> https://chromium.googlesource.com/chromium/src/+/refs/heads/main/chrome/common/pref_names.cc https://stackoverflow.com/a/59953341/18220200
this is my code. I can't find wrong points, would appreciate any advice.
#Chromedriver pdf print setting
chromeoptions = webdriver.ChromeOptions()
chromeSettings = {"recentDestinations": [{
"id" : "Save as PDF",
"origin" : "local",
"account" : ""}],
"selectedDestinationID" : "Save as PDF",
"version" : 2,
}
chromeoptions.add_argument('--enable-print-browser')
chromeoptions.add_argument("--safebrowsing-disable-download-protection")
chromeoptions.add_argument("safebrowsing-disable-extension-blacklist")
prefs = {'printing.print_preview_sticky_settings.appState' : json.dumps(chromeSettings)}
chromeoptions.add_experimental_option('prefs', prefs)
chromeoptions.add_experimental_option("prefs", {
"download.default_directory": r"filepath",
'behavior': 'allow',
"download.directory_upgrade": True,
'download.prompt_for_download': False,
'download.extensions_to_open': 'pdf:xls:xml',
'safebrowsing.enabled': True,
'popups' : False
})
+I added my codes, 'print part'
clickByXpath('//print_button')
# Open chrome print window
time.sleep(1)
pyautogui.press('enter')
filename = '\Report' + str(filename+1)
time.sleep(7) #wait for 'save as' window
pyautogui.typewrite(constants.FILE_DOWNLOAD_LOCATION + filename)
pyautogui.press('enter')
time.sleep(1)
driver.switch_to.window(now_window)
pyautogui.hotkey('ctrl', 'w')