python selenium (十二) 鼠标操作

from selenium.webdriver import ActionChains

element = driver.find_element(By.ID, 'login')
start = driver.find_element(By.ID, 'start')
end = driver.find_element(By.ID, 'end')

action_chains = ActionChains(driver)  # 实例化ActionChains对象
#  move_to_element() 移动到需要被定位元素位置
#  click()  左击
#  double_click()  双击
#  context_click()  右击
#  drag_and_drop()  拖拽
#  perform()  存储在ActionChains()对象的行为,然后提交
action_chains.move_to_element(element).click().perform()
action_chains.move_to_element(element).double_click().perform()
action_chains.move_to_element(element).context_click().perform()
action_chains.drag_and_drop(start, end).perform()
action_chains.move_to_element(element).perform()  # 悬停
posted @ 2025-02-26 23:06  アーニャ  阅读(26)  评论(0)    收藏  举报