Python3 + seleium鼠标移动拖拽双击、长按等操作
Python3 + seleium鼠标移动拖拽双击、长按等操作
1、move_to_ element(to_element)鼠标移动到指定元素
element = driver.find_element_by_id('xxx') ActionChains(driver).move_to_element(element).perform()
2、move_ to_ element_ with_ offset(to_element, xoffset, yoffset)
鼠标往右上方横向纵向各移动100
element = driver.find_element_by_id('xxx') ActionChains(driver).move_to_element_with_offset(element, 100, 100).perform()
3、double_click(on_element=None)
双击元素,如果没有指定元素则在当前鼠标位置双击
element = driver.find_element_by_id('xxx') ActionChains(driver).double_click(element).perform()
4、context_click(on_ element=None)
在元素上点击鼠标右键,如果没有指定则在当前鼠标位置单击右键
element = driver.find_element_by_id('xxx') ActionChains(driver).context_click(element).perform()
5、click_and_hold(on_element=None) 鼠标按下不松
element = driver.find_element_by_id('xxx' ) ActionChains(driver).click_and_hold(element).perform()
6、drag_and_drop(source, target)
按住element1元素,拖动到element2元素。
element1 = driver.find_element_by_id('source" ) element2 = driver.find_element_by_id('target' ) ActionChains(driver).drag_and_drop(element1, element2).perform()
7、drag_and_drop_ by_ ofet(source_xoffset, yofiset)
向左上角横向纵向移动100。
element = driver.find_element_by_id('source') ActionChains(driver).drag_and_drop_by_offset(element, -100, -100).perform()