from selenium import webdriver#引入keys模块from selenium.webdriver.common.keys import Keysdriver = webdriver.Chrome()driver.get("https://www.baidu.com")#输入框输入内容driver.find_element_by_id("kw").send_keys("selenium")#删除多输入的一个mdriver.find_element_by_id("kw").send_keys(Keys.BACK_SPACE)#输入空格键+教程driver.find_element_by_id("kw").send_keys(Keys.SPACE)driver.find_element_by_id("kw").send_keys("教程")#全选输入框内容driver.find_element_by_id("kw").send_keys(Keys.CONTROL,"a")#剪切输入框内容driver.find_element_by_id("kw").send_keys(Keys.CONTROL,"x")#粘贴内容到输入框driver.find_element_by_id("kw").send_keys(Keys.CONTROL,"v")#通过回车键代替单击操作driver.find_element_by_id("su").send_keys(Keys.ENTER)#制表键:driver.find_element_by_id("su").send_keys(Keys.TAB)#回退键driver.find_element_by_id("su").send_keys(Keys.ESCAPE)#复制driver.find_element_by_id("su").send_keys(Keys.CONTROL,"c")#键盘F1driver.find_element_by_id("su").send_keys(Keys.F1)
来源:https://www.cnblogs.com/zhang-da/p/12210767.html