selenium:鼠标事件

 

需要导入action的模块:

from selenium.webdriver.common.action_chains import ActionChains

 

一、右击

#右击
    def right(self,element):
        try:
            ri = self.driver.find_element(*element)
            ActionChains(self.driver).context_click(ri).perform()
        except:
            print("没找到元素:" + str(element))
            raise

 二、双击

    def double(self,element):
        try:
            ri = self.driver.find_element(*element)
            ActionChains(self.driver).double_click(ri).perform()
        except:
            print("没找到元素:" + str(element))
            raise

 

三、拖放

复制代码
    def drop(self,element,target):
        try:
            #起始位置
            ri1 = self.driver.find_element(*element)
            #目的位置
            ri2 = self.driver.find_element(*target)
            ActionChains(self.driver).drag_and_drop(ri1,ri2).perform()
        except:
            print("没找到元素:" + str(element/target))
            raise
复制代码

 

 

四、移动到/悬停位置

    def move_stop(self,element):
        try:
            ri = self.driver.find_element(*element)
            ActionChains(self.driver).move_to_element(ri).perform()
        except:
            print("没找到元素:" + str(element))
            raise

 

 

五、按下鼠标左键不弹起

    def left_hond(self,element):
        try:
            ri = self.driver.find_element(*element)
            ActionChains(self.driver).click_and_hold(ri).perform()
        except:
            print("没找到元素:" + str(element))
            raise

 

posted @   冯立挺  阅读(172)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示