selenium/ui自动化键盘的操作
作者:互联网
'''
键盘操作:
使用键盘操作时 首先应该导入
from selenium.webdrive.common.keys import keys #导入Keys类
'''
from selenium.webdriver.common.keys import Keys
driver.find_element_by_id('kw').send_keys('大佬6666')
sleep(1)
driver.find_element_by_id('kw').send_keys(Keys.BACK_SPACE)#点击键盘backpace删除
driver.find_element_by_id('kw').send_keys(Keys.CONTROL,'a')#ctrl全选
sleep(1)
driver.find_element_by_id('kw').send_keys(Keys.CONTROL,'x')#剪切
sleep(1)
driver.find_element_by_id('kw').send_keys(Keys.CONTROL,'v')#粘贴
sleep(1)
driver.find_element_by_id('kw').send_keys(Keys.CONTROL,'c')#复制
driver.find_element_by_id('kw').send_keys(Keys.ENTER)#点击确定)
'''
封装一个元素定位的方法:
'''
def find_id(local,*valuse):
return driver.find_element_by_id(local).send_keys(valuse)
if __name__ == '__main__':
find_id('kw','python')#点击键盘backpace删除一格
sleep(1)
find_id('kw',Keys.CONTROL,'a')#ctrl全选)
sleep(1)
find_id('kw',Keys.CONTROL,'x')#剪切
sleep(1)
find_id('kw',Keys.CONTROL,'v')#粘贴
sleep(1)
find_id('kw',Keys.CONTROL,'c')#复制
sleep(1)
find_id('kw',Keys.ENTER)#点击确定
'''
封装脚本:
没有封装叫线性脚本 可以封装在类里面
'''
标签:Keys,selenium,find,键盘,keys,ui,kw,id,sleep 来源: https://www.cnblogs.com/manxingsir/p/15012807.html