模擬鼠標事件
1.from selenium.webdriver.common.action_chains import ActionChains
2:ActionChains(driver):用於生成模擬用戶行爲
3:perform():執行存儲行爲
表達式 | 說明 |
---|---|
context_click | 右擊事件 |
double_click | 雙擊事件 |
drag_and_drop | 拖動 |
move_to_element() | 鼠標停在一個元素上 |
click_and_hold | 按下鼠標左鍵在一個元素上 |
example: ActionChains(driver).move_to_element(ele).perform()
模擬鍵盤事件
send_keys()
from selenium.webdriver.common.keys import Keys
表達式 | 說明 |
---|---|
send_kyes(Kyes.BACK_SPACE) | 退格鍵 |
send_kyes(Kyes.CONTRL, 'a') | 全選 |
send_kyes(Kyes.CONTRL, 'v') | 粘貼 |
send_kyes(Kyes.CONTRL, 'c') | 複製 |
send_kyes(Kyes.CONTRL, 'x') | 剪切 |
send_kyes(Kyes.ENTER) | 回車 |