5

I am trying to render a page which on load automatically shows the print dialog. I want to skip it using selenium. I searched on internet but couldn't find any suitable example since most of example handles javascript alert not windows alert.

I also install python robotframework because many people suggested it but couldn't find any example for that either.

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

NOTE: This question is in continuation of my previous question. python selenium not updating pop up window url

Oleksandr Makarenko
  • 779
  • 1
  • 6
  • 18
Manish Gupta
  • 4,438
  • 18
  • 57
  • 104

2 Answers2

1

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

driver.execute_script("window.print = function(){};")
Florent B.
  • 41,537
  • 7
  • 86
  • 101
  • Place it after the get command and before the click action. Note that each reload/refresh of the page will reset the print function. – Florent B. May 13 '16 at 11:26
  • 2
    There is no click function. The print dialog appears automatically on page load. I just want to skip it. I tried putting it both after and before the but it does not skip the print dialog. – Manish Gupta May 13 '16 at 11:29
1

Using Firefox you could set some profile options that effectively silence the print dialog popup.

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")
sowa
  • 1,249
  • 16
  • 29