这个是python+selenium之键盘事件
- #coding=utf-8
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- #导入keys模块
- import time
- driver = webdriver.Firefox()
- driver.get('http://www.baidu.com')
- driver.find_element_by_id("kw").send_keys("selenium+")
- driver.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(u"教程")
- #输入教程
- driver.find_element_by_id("kw").send_keys(Keys.CONTROL,'a')
- time.sleep(2)
- #ctrl+a
- driver.find_element_by_id("kw").send_keys(Keys.CONTROL,'x')
- time.sleep(2)
- #ctrl+x
- driver.find_element_by_id("kw").send_keys(Keys.CONTROL,'v')
- time.sleep(2)
- #ctrl+v
- driver.find_element_by_id("su").send_keys(Keys.ENTER)
- #使用enter代替单机操作
- time.sleep(4)
- #等等4秒
- driver.quit()
- #关闭浏览器