

I decided to look at the source code for mozilla gecko-dev for a potential solution. t_preference("print.print_to_filename", "/tmp/file.pdf") t_preference("print.print_to_file", True) Some of the bug reports mentioned that certain switches used in the print process no longer worked. Again this was a problem that others had. After seeing that this was a problem, I looked through the issues in selenium and the bug reports for mozilla. When I looked through Stack Overflow for inspiration, I discover multiple open question on printing pdf using the geckodriver with selenium. The geckodriver doesn't have 'execute_cdp_cmd'. With the 'chromedriver' you can call the function 'execute_cdp_cmd' and pass Page.printToPDF. I was shocked how hard it was to print to a PDF using the geckodriver and selenium. I wanted to save the output to PDF vs printing to paper. These solutions will either print the active webpage to your local printer or to a PDF file without having to deal with the dialog. JavascriptException: TypeError: document.querySelector(.) is nullīoth the solutions below are designed NOT to launch the print dialog. "return document.querySelector('print-preview-app').shadowRoot.querySelector('#sidebar').shadowRoot.querySelector('print-preview-button-strip').shadowRoot.querySelector('.action-button')")īrowser.switch_to.window(driver.window_handles) # action_chains.move_to_element(element).click().perform()īrowser.switch_to.window(browser.window_handles) # element = browser.find_element_by_xpath(xpath_string) # xpath_string = '/html/body/div/div/div/div/div/div/div/div/div/div/div/section/div/ul/li/a/span' Profile = FirefoxProfile('C:\\Users\\\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\fault-release') My full updated code as per input from from selenium.webdriver import Firefoxįrom import Selectįrom import Optionsįrom _profile import FirefoxProfileįrom selenium.webdriver import DesiredCapabilitiesįrom import NoSuchElementException

Is there a way to bypass this dialog box and directly print since this is not a system dialog box but Firefox's.

Xpath_string = '/html/body/div/div/div/div/div/div/div/div/div/div/div/section/div/ul/li/a/span'Įlement = browser.find_element_by_xpath(xpath_string)Īction_chains.move_to_element(element).click().perform()īrowser.execute_script('window.print() ')Ī print dialog box pops up for Firefox. t_preference("", "application/pdf")Įlement_search_field = browser.find_element_by_id(search_field_id)Įlement_search_nd_keys(Keys.ENTER)įrom selenium.webdriver import ActionChainsĪction_chains.key_down(Keys.CONTROL).send_keys('V').key_up(Keys.CONTROL).perform() I have the following code: from selenium.webdriver import Firefoxįrom import Keysīrowser = Firefox(executable_path = driver_path)
