(selenium系列之四)webdriver 操作鼠标

ActionChains 类提供了鼠标操作常用的方法:

perform()   执行所有ActionChains中存储的行为

context_click()  右击

double_click() 双击

drag_and_drop() 拖动

move_to_element() 鼠标悬停

#coding=utf-8

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()
driver.get("http://www.baidu.cn")

#鼠标右击
right_click = driver.find_element_by_id('xx')
ActionChains(driver).context_click(right_click).perform()

#鼠标悬停
above = driver.find_element_by_id("id")
ActionChains(driver).move_to_element(above).perform()

#鼠标拖放
start_ele = driver.find_element_by_id("id1")
end_ele = driver.find_element_by_id('id2')
ActionChains(driver).drag_and_drop(start_ele,end_ele).perform()

猜你喜欢

转载自blog.csdn.net/m0_37553368/article/details/81634239