Google Chrome for Testing kiosk printing not saving my PDF

125 Views Asked by At

I'm using Selenium to open a series of web pages that each have a window.print() when the form is loaded. I'm fairly sure in the past I have successfully used this code with the chromium driver to print the pages to pdf in the directory I have requested, but I believe Google Chrome for Testing 117.0.5938.92 is respecting the options I've selected for kiosk printing and the default location, but I can't figure out why it's not producing a file to the proper location.

import json
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options

printdir="/Users/username/Downloads/mydirectory"

print_settings = {
    "recentDestinations": [{
        "id": "Save as PDF",
        "origin": "local",
        "account": ""
    }],
    "selectedDestinationId": "Save as PDF",
    "version": 2
}

prefs = {
    "printing.print_preview_sticky_settings.appState": json.dumps(print_settings),
    "download.default_directory": printdir,
    "savefile.default_directory": printdir,
    "safebrowsing.enabled": True
}

options = Options()
options.add_experimental_option('prefs', prefs)
options.add_argument('--kiosk-printing') 

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)

recordlist = ['123', '456']

for record in recordlist:
    url = f"https://website.com/printarticle.php?article_id={record}"
    driver.get(url)

It seems to do as it should opening the print dialog and generating the preview, and then it just disappears (which is what it should do), but I don't see the file anywhere. I checked chrome://downloads but I don't believe print to PDF would appear there. At least it didn't when I printed another page. If I open a new tab and print that it goes exactly where it's supposed to.

On a lark I also tried --disable-print-preview in case there's something going wrong in the print preview, but that gets me a dialog box, and from what I've read this breaks kiosk-printing. Is there anything in the console that would tell me what's happening with the print preview window?

0

There are 0 best solutions below