1. 程式人生 > >鼠標和鍵盤事件

鼠標和鍵盤事件

ont src 雙擊 url image sele mage clas ref

ActionChains類與輸入事件

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

按下鼠標左鍵在一個元素上

鍵盤事件: 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)

回車

context_click 鼠標右擊事件
#導入 ActionChains 用於生成模擬用戶行為
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from time import sleep

# context_click 鼠標右擊事件
url = https://www.baidu.com/ driver = webdriver.Firefox() driver.get(url) c_click = driver.find_element_by_css_selector(#su) ActionChains(driver).context_click(c_click).perform()
技術分享圖片


鼠標和鍵盤事件