Keys()類提供了快速鍵的方法
經常是用到的快速鍵操作
send_keys(Keys.BACKSPACE) 刪除鍵
send_keys(keys.ENTER) 斷行符號鍵
send.keys(Keys.SPACE) 空格鍵
send.keys(Keys.CONTROL,'a') 快速鍵control+A
send.keys(Keys.CONTROL,'c') 快速鍵control+C
#coding=utf-8from selenium import webdriver#匯入Keys()類from selenium.webdriver.common.keys import Keysdriver = webdriver.Firefox()driver.get('https://www.baidu.com')driver.find_element_by_id('kw').send_keys('seleniumm')#刪除多餘的一個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(u'教程')#全選輸入框內容,使用control+Adriver.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('kw').send_keys(Keys.ENTER)driver.quit()