Python - Selenium - How to use Browser Shortcuts

后端 未结 4 1166
遥遥无期
遥遥无期 2020-12-19 08:51

Once a browser page is loaded I\'m looking to use the CRTL+P shortcut in Goggle Chrome to enter the print page and then simply press return to print the page.



        
4条回答
  •  醉酒成梦
    2020-12-19 09:24

    I have tested this on Google Chrome and the problem can be solved using a combination of .key_down() and .send_keys() methods of the ActionChains class.

    ActionChains(driver).key_down(Keys.CONTROL).send_keys('p').key_up(Keys.CONTROL).perform()
    ActionChains(driver).send_keys(Keys.ENTER)
    

提交回复
热议问题