概述
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)
from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys ActionChains(browser).send_keys(Keys.CONTROL,"p").perform()
这将发送打印对话框的键盘快捷方式
我没有找到一种方法在FF中进行打印但是 – ctrl p将打开打印对话框,但FF有一个焦点错误,不允许人们为对话框本身做Keys.ENTER
希望这对你在Chrome中有用,我还没有在那里测试过
如果你找到解决方法,请更新 – 可能尝试AutoIt
如果以上都不起作用,你可以随时做
browser.get_screenshot_as_file( path + 'page_image.jpg' )
总结
以上是编程之家为你收集整理的Python – Selenium – 如何使用浏览器快捷方式全部内容,希望文章能够帮你解决Python – Selenium – 如何使用浏览器快捷方式所遇到的程序开发问题。
如果您也喜欢它,动动您的小指点个赞吧