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

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

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)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwsgwy.html