引入ActionChains模块
from selenium.webdriver.common.action_chains import ActionChains
ActionChains类提供的鼠标事件方法
perform() | 执行所有ActionChains存储的事件 |
---|---|
context_click() | 右击 |
double-click() | 双击 |
drag_and_drop() | 拖动 |
move_to_element() | 悬停 |
click_and_hold() | 在一个元素上按下鼠标左键并保持 |
创建ActionChains对象
#用driver
Action = ActionChains(driver)
右击事件
element =driver.find_element_by_xpath('//*[@id="su"]')
Action.move_to_element(element).context_click().perform()
move_to_element定位到搜索按钮上,context_click()右击,
perform()提交之前的操作
效果截不下来,就算了
双击
element =driver.find_element_by_xpath('//*[@id="su"]')
Action.move_to_element(element).double_click().perform()
一般web测试用的不多,知道用法就好了
拖动
first_element = driver.find_element_by_xpath('某个元素的xpath')
two_element = dirver.find_element_by_xpath('第二个元素的xpath')
Action.drag_to_drop(first_element,two_element).perform()
按住
Action.move_to_element(element).click_and_hold().perform()
鼠标常用事件就这么多了,下期讲键盘操作。