I want to have selenium: open a page, sleep for 10 seconds (ensure everything has loaded), then print the webpage. Neither of the two solutions, using javascript to print the page, or using send_keys
works.
profile = FirefoxProfile(PATH_TO_PROFILE_HERE)
profile.set_preference("print.always_print_silent", True)
profile.set_preference("print.printer_Microsoft_Print_to_PDF.print_to_file", True)
profile.set_preference("print.printer_Microsoft_Print_to_PDF.print_to_filename", file_location)
driver = webdriver.Firefox(profile)
driver.get(URL_HERE)
time.sleep(10)
# Neither one of these two seem to work.
# driver.execute_script('window.print();')
# driver.find_element_by_css_selector("body").send_keys(Keys.CONTROL, "p")
When I manually go on to the problem page (using the profile with the preferences set appropriately), I'm able to use Ctrl+P
and it prints without a dialogue box on where to print/what to name it.
The problem is intermittent, it will work on www.google.com
but not some other websites? Has anyone found a way to get print to work 100% of the time?
Related Problem: Automate print/save web page as pdf in chrome - python 2.7