I'm having a hard time initiating the 'print' event on google chrome using selenium.
I've tried all the following both on OSX and Windows with no luck. For OSX I've replaced Keys.CONTROL
with Keys.COMMAND
/Keys.META
.
driver = webdriver.Chrome()
driver.get("http://google.com")
# 1st try
actions = ActionChains(driver)
actions.move_to_element(driver.find_element_by_tag_name('body'))
actions.key_down(Keys.CONTROL).send_keys('p').key_up(Keys.CONTROL)
actions.perform()
# 2nd try
ActionChains(driver).key_down(Keys.CONTROL).send_keys('p').key_up(Keys.CONTROL).perform()
# 3rd try
ActionChains(driver).send_keys(Keys.CONTROL, "p").perform()
# 4th try
driver.find_element_by_tag_name("body").send_keys(Keys.CONTROL + 'p')
None of the above did the trick. The only method that worked is driver.execute_script("window.print()")
, but that is not the behaviour I'm looking for in this case.
Chrome driver version 80.0.3987.106.
Any ideas? Is there a way to initiate the 'print' event without the use of hotkeys?