selenium2 python中的悬停操作

来源:互联网 发布:淘宝销量多久清零 编辑:程序博客网 时间:2024/05/22 06:46

参考资料:http://wenku.it168.com/d_001149474.shtml

在实际应用中,有的时候 一个元素的显示需要鼠标悬停后,该元素才是可见的. 想要点击这个隐藏的元素就要分成两步来进行操作

1/ 鼠标移动到展示元素处(让元素从隐藏变成可见可点击)

2/鼠标点击该元素

参考网上大拿们的建议 ,在selenium中 加载from selenium.webdriver.common.action_chains import *

主要应用的函数为 move_to_element

具体方法介绍为:

    def move_to_element(self, to_element):
        """
        Moving the mouse to the middle of an element.


        :Args:
         - to_element: The element to move to.
        """
        self._actions.append(lambda:
            self._driver.execute(Command.MOVE_TO, {'element': to_element.id}))
        return self


具体实例:

def ebay_case():    a=init    #加载初始化数据    implement=a.browser.find_element_by_link_text("客服管理")   #识别需要悬停的元素    chain=ActionChains(a.browser)     #引用<span style="font-family: Arial, Helvetica, sans-serif;">ActionChains类  继承a.brwoser </span>    chain.move_to_element(implement).perform()     #鼠标移到悬停元素上


0 0
原创粉丝点击