常用方法
删除键:send_keys(Keys.BACK_SPACE)
空格键:send_keys(Keys.SPACE)
制表键:send_keys(Keys.TAB)
回退键:send_keys(Keys.ESCAPE)
回车键:send_keys(Keys.ENTER)
全选:send_keys(Keys.CONTROL,“a”)
复制:send_keys(Keys.CONTROL,“c”)
粘贴:send_keys(Keys.CONTROL,“v”)
剪切:send_keys(Keys.CONTROL,“x”)
F1:send_keys(Keys.F1)文章来源地址https://www.toymoban.com/news/detail-771821.html
实现代码
"""
键盘操作
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
# 调用keys模块
from selenium.webdriver.common.keys import Keys
import time
url = "https://www.baidu.com"
driver = webdriver.Chrome()
driver.get(url)
# 在输入框输入内容
driver.find_element(By.ID,"kw").send_keys("模拟键盘操作做")
time.sleep(3)
# 删除“做”字
driver.find_element(By.ID,"kw").send_keys(Keys.BACK_SPACE)
time.sleep(3)
# 输入空格 + “教程”
driver.find_element(By.ID,"kw").send_keys(Keys.SPACE)
driver.find_element(By.ID,"kw").send_keys("教程")
time.sleep(3)
# 全选
driver.find_element(By.ID,"kw").send_keys(Keys.CONTROL,'a')
time.sleep(3)
# 剪切
driver.find_element(By.ID,"kw").send_keys(Keys.CONTROL,'x')
time.sleep(3)
# 复制
driver.find_element(By.ID,"kw").send_keys(Keys.CONTROL,'v')
time.sleep(3)
# 用回车键代替单击操作
driver.find_element(By.ID,"su").send_keys(Keys.ENTER)
time.sleep(3)
driver.quit()
文章来源:https://www.toymoban.com/news/detail-771821.html
到了这里,关于6、selenium 键盘操作的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!