加载浏览器页面后,我希望使用Goggle Chrome中的CRTL P快捷键进入打印页面,然后只需按返回即可打印页面.
import time
from selenium import webdriver
# Initialise the webdriver
chromeOps=webdriver.ChromeOptions()
chromeOps._binary_location = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
chromeOps._arguments = ["--enable-internal-flash"]
browser = webdriver.Chrome("C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe",port=4445,chrome_options=chromeOps)
time.sleep(3)
# Login to Webpage
browser.get('www.webpage.com')
我的问题是如何将密钥发送到浏览器本身而不是元素?
尝试失败:将html主体指定为元素并将密钥发送给 –
elem = browser.find_element_by_xpath("/html/body") # href link
elem.send_keys(Keys.CONTROL + "P") # Will open a second tab
time.sleep(3)
elem.send_keys(Keys.RETURN)