python+selenium自动化测试鼠标双击、鼠标悬停、右键点击、鼠标拖动

1、鼠标双击

例如有些地方需要使用到双击修改信息等,就需要使用到鼠标双击模拟操作

from selenium import webdriver

from selenium.webdriver import ActionChains

action_chains = ActionChains(self.driver)

action_chains.double_click(self.driver.find_element(By.ID,"span_shorturl")).perform()

2、右键单击

例如右键之后会出现菜单

from selenium import webdriver

from selenium.webdriver import ActionChains

action_chains = ActionChains(self.driver)

action_chains.context_click(self.driver.find_element(By.ID,"span_shorturl")).perform()

3、鼠标悬停

from selenium import webdriver

from selenium.webdriver import ActionChains

action_chains = ActionChains(self.driver)

action_chains.move_to_element(self.driver.find_element(By.ID,"span_shorturl")).perform()

4、鼠标拖动:比如 拖动某个对象、拖动滚动条 

#定位元素的源位置

source = driver.find_element_by_id("id")

#定位元素要移到到的目标位置
target = driver.find_element_by_id("id")

action_chains = ActionChains(self.driver)

action_chains .drag_and_drop(source,target).perform()

 

posted @ 2020-10-07 15:55  CWZzzzz  阅读(1743)  评论(0编辑  收藏  举报