引入ActionChains类:from selenium.webdriver.common.action_chains import ActionChains
26.右击
方法:context_click()
实例:ActionChains(driver).context_click(driver.find_element_by_id("id")).perform()
27.双击
方法:double_click()
实例:ActionChains(driver).double_click(driver.find_element_by_name("name")).perform()
28:鼠标拖放
方法:drag_and_drop(source, target)
source:鼠标按下的源元素;target:鼠标释放的目标元素
实例:element = driver.find_element_by_name("name")
target = driver.find_element_by_name("name")
ActionChains(driver).drag_and_drop(element, target).perform()
29:鼠标悬停在一个元素上(hover)
方法:move_to_element()
实例:above = driver.find_element_by_xpath("xpath路径")
ActionChains(driver).move_to_element(above).perform()
30:按下鼠标左键在一个元素上
方法:click_and_hold()
实例:left = driver.find_element_by_name("name")
ActionChains(driver).click_and_hold(left).perform()
ActionChains类鼠标操作的常用方法
最新推荐文章于 2024-12-19 15:44:43 发布