Set Selenium ChromeDriver UserPreferences to Save as PDF

前端 未结 1 724
清酒与你
清酒与你 2020-12-17 05:39

I am using ChromeDriver 2.33 and am using kiosk printing to automatically click the Print button on the Print Preview dialog however it is sending the document to the printe

相关标签:
1条回答
  • 2020-12-17 06:22

    try adding Save as PDF on recentDestinations:

    import json
    settings = {
        "appState": {
            "recentDestinations": [{
                "id": "Save as PDF",
                "origin": "local"
            }],
            "selectedDestinationId": "Save as PDF",
            "version": 2
        }  
    }
    prefs = {'printing.print_preview_sticky_settings': json.dumps(settings)}
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_experimental_option('prefs', prefs)
    chrome_options.add_argument('--kiosk-printing')
    
    driver = webdriver.Chrome(chrome_options=chrome_options)
    
    0 讨论(0)
提交回复
热议问题