How to reject a print dialog in selenium?

I am trying to display a page that, when loaded, automatically displays a print dialog. I want to skip it with selenium. I searched on the Internet but did not find a suitable example, since most examples handle a javascript warning, not a Windows warning.

I also install python robotframeworkbecause many people suggested it, but could not find a single example for this.

My question is how to disable windows alert using selenium and robotframework in python?

NOTE. This question is a continuation of my previous question. python selenium does not update window url up

+4
source share
2 answers

I could avoid the print window by overriding the function window.print:

driver.execute_script("window.print = function(){};")
+1
source

Using Firefox, you can set some profile options that have effectively disabled the print popup dialog.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

profile = webdriver.FirefoxProfile()
profile.set_preference("print.always_print_silent", True)
profile.set_preference("print.show_print_progress", False)

driver = webdriver.Firefox(profile)
driver.get("http://www.google.com")

# Send print instruction
elem = driver.find_element_by_xpath("//body")
elem.send_keys(Keys.COMMAND, "p")
+1
source

All Articles