selenium save webpage as pdf python

Solutions on MaxInterview for selenium save webpage as pdf python by the best coders in the world

showing results for - "selenium save webpage as pdf python"
Simon
06 Jun 2018
1from selenium import webdriver
2import json
3
4chrome_options = webdriver.ChromeOptions()
5settings = {
6       "recentDestinations": [{
7            "id": "Save as PDF",
8            "origin": "local",
9            "account": "",
10        }],
11        "selectedDestinationId": "Save as PDF",
12        "version": 2
13    }
14prefs = {'printing.print_preview_sticky_settings.appState': json.dumps(settings)}
15chrome_options.add_experimental_option('prefs', prefs)
16chrome_options.add_argument('--kiosk-printing')
17CHROMEDRIVER_PATH = '/usr/local/bin/chromedriver'
18driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=CHROMEDRIVER_PATH)
19driver.get("https://google.com")
20driver.execute_script('window.print();')
21driver.quit()
22