Selenium Printing Error The Selected Printer Could Not Be Found
This is in reference to the solution provided by @lifeiscomplex How to handle Firefox print dialog box in Selenium The code is: from time import sleep from selenium import webdrive
Solution 1:
In the comments of this question "How to handle Firefox print dialog box in Selenium" you mentioned that you had changed this line from my answer:
profile_options.set_preference('print.printer_Mozilla_Save_to_PDF.print_to_file.print_to_filename', "testprint.pdf")
to this:
profile_options.set_preference('print.printer_Microsoft_Print_to_PDF.print_to_filename', "testprint.pdf")
If you want to change that line you would have to change at least one more in the code you posted.
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.options import FirefoxProfile
driver_path = 'geckodriver.exe'
firefox_options = Options()
firefox_options.add_argument("--disable-infobars")
firefox_options.add_argument("--disable-extensions")
firefox_options.add_argument("--disable-popup-blocking")
profile_options = FirefoxProfile()
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11.5; rv:90.0) Gecko/20100101 Firefox/90.0'
profile_options.set_preference('profile_options = FirefoxProfile()', user_agent)
# this line was changed
profile_options.set_preference("print_printer", "Microsoft Print to PDF")
profile_options.set_preference("print.always_print_silent", True)
profile_options.set_preference("print.show_print_progress", True)
profile_options.set_preference('print.save_as_pdf.links.enabled', True)
# this line was changed
profile_options.set_preference("print.printer_Microsoft_Print_to_PDF.print_to_file", True)
# this line was changed
profile_options.set_preference('print.printer_Microsoft_Print_to_PDF.print_to_filename', "testprint.pdf")
driver = webdriver.Firefox(executable_path=driver_path, options=firefox_options,
firefox_profile=profile_options)
URL = 'https://finance.yahoo.com/'
driver.get(URL)
search_field_id = 'yfin-usr-qry'
element_search_field = driver.find_element_by_id(search_field_id)
element_search_field.clear()
element_search_field.send_keys('TSLA')
element_search_field.send_keys(Keys.ENTER)
driver.execute_script("window.print()")
sleep(20)
driver.quit()
There might be another line that needs to be changed, but I cannot test the code above to verify this, because I'm using macOS and not Windows 10.
You also mentioned that you commented this line out:
profile_options.set_preference("print.always_print_silent", True)
commenting out this line will launch the print dialog
as showed in the graphic below.
Post a Comment for "Selenium Printing Error The Selected Printer Could Not Be Found"