'Converting Chromedriver to FirefoxDriver with selenium in python3
I tried to make some automation saving pages into PDF file. The problem is that Chromedriver has some bugs with changing print sizes. No matter how I adjust it, it just save the page with default size.
I've asked it to selenium github, and they said it works with Firefox while it doesn't work with Chrome driver.
I haven't used selenium with Firefox. And clearly, it doesn't support 'add_experimental_option' as well.
I also tried to look for how to print - save to PDF from the scratch with Firefox, but most of the codes are using pyguiauto, and clicking it.
Can I convert this codes to Firefox, geckodriver?
chrome_options = webdriver.ChromeOptions()
settings = {
"recentDestinations": [{
"id": "Save as PDF",
"origin": "local",
"account": ""
}],
"selectedDestinationId": "Save as PDF",
"version": 2,
"mediaSize": {
"height_microns": 355600,
"width_microns": 215900,
"name": "NA_legal",
"custom_display_name": "legal"
},
"isCssBackgroundEnabled": True,
"isHeaderFooterEnabled": True,
}
prefs = {'printing.print_preview_sticky_settings.appState' : json.dumps(settings)}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--kiosk-printing')
chrome_options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome("chromedriver.exe", options=chrome_options)
driver.get('page')
driver.execute_script('window.print();')
Thanks for helping me out.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
