selenium键盘事件

#coding=utf-8

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys #打开狐火浏览器
driver = webdriver.Firefox()
#访问目标网址
driver.get("http://127.0.0.1:80/iwebshop")
driver.maximize_window() #打印当前页面title
title = driver.title
print (title) #打印当前页面 URL
now_url = driver.current_url
print (now_url) #获得用户名
user = driver.find_element_by_name('').text
print (user) if user = '':
print ('login success!')
else:
print ('login error') driver.find_element_by_id('word').send_keys('ipadd') #删除多输入的一个 d
driver.find_element_by_id('word').send_keys(Keys.BACK_SPACE )
#输入空格键+“教程”
driver.find_element_by_id('word').send_keys(Keys.SPACE)
driver.find_element_by_id('word').send_keys(u'教程')
#输入Ctrl+a
driver.find_element_by_id('word').send_keys(Keys.CONTROL,'a')
driver.find_element_by_id('word').send_keys(Keys.CONTROL,'x')
driver.find_element_by_id('word').send_keys(Keys.CONTROL,'v')
"""
send_keys(Keys.BACK_SPACE) 删除键(BackSpace) send_keys(Keys.SPACE) 空格键(Space) send_keys(Keys.TAB) 制表键(Tab) send_keys(Keys.ESCAPE) 回退键(Esc) send_keys(Keys.ENTER) 回车键(Enter) send_keys(Keys.CONTROL, ‘a’) 全选(Ctrl+A) send_keys(Keys.CONTROL, ‘c’) 复制(Ctrl+C) send_keys(Keys.CONTROL, ‘x’) 剪切(Ctrl+X) send_keys(Keys.CONTROL, ‘v’) 粘贴(Ctrl+V) send_keys(Keys.F1) 键盘 F1
...
send_keys(Keys.F12) 键盘 F12
"""
time.sleep(4)
driver.quit()

  

05-12 15:33