您好,登錄后才能下訂單哦!
Keys類提供了鍵盤上所有的按鍵方法。send_keys方法用來模擬鍵盤輸入
如下代碼:
from time import * from selenium import webdriver #引入Keys模塊 from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() url = "https://www.baidu.com" print('new access %s' %(url)) driver.get(url) #輸入框輸入內容 driver.find_element_by_id('kw').send_keys('seleniumm') #刪除多輸入的一個m 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('教程') sleep(3) #全選輸入框 driver.find_element_by_id('kw').send_keys(Keys.CONTROL,'a') #剪切輸入框 sleep(3) driver.find_element_by_id('kw').send_keys(Keys.CONTROL,'x') #粘貼輸入框 sleep(3) driver.find_element_by_id('kw').send_keys(Keys.CONTROL,'v') #回車代替click sleep(3) driver.find_element_by_id('kw').send_keys(Keys.ENTER) sleep(10) driver.quit()
常用鍵盤操作:
send_keys(Keys.BACK_SPACE)刪除鍵(BackSpace)
send_keys(Keys.SPACE) 空格鍵
send_keys(Keys_TAB) 制表鍵
send_keys(Keys_ESCAPE) 回退鍵
send_keys(Keys_ENTER) 回車鍵
send_keys(Keys.CONTRAL,'a') 全選(Ctrl+A)
send_keys(Keys.CONTRAL,'c') 復制(Ctrl+C)
send_keys(Keys.CONTRAL,'x') 剪切(Ctrl+X)
send_keys(Keys.CONTRAL,'v') 粘貼(Ctrl+V)
send_keys(Keys.F1) 鍵盤F1
....
send_keys(Keys.F12) 鍵盤F12
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。