zoukankan      html  css  js  c++  java
  • Selenium WebDriver- actionchians模拟鼠标悬停操作

    #encoding=utf-8
    import unittest
    import time
    from selenium import webdriver
    from selenium.webdriver import ActionChains
    
    class VisitSogouByIE(unittest.TestCase):
    
        def setUp(self):
            #启动IE浏览器
            #self.driver = webdriver.Firefox(executable_path = "e:\geckodriver")
            self.driver = webdriver.Ie(executable_path = "e:\IEDriverServer")
            
        def test_roverOnElement(self):
            url = "http://127.0.0.1/test_mouse_hover.html"
            # 访问自定义的html网页
            self.driver.get(url)
            # 找到页面上第一个链接元素
            link1 = self.driver.find_element_by_partial_link_text(u"指过来1")
            # 找到页面上第二个链接元素
            link2 = self.driver.find_element_by_partial_link_text(u"指过来2")
            # 找到页面上的p元素
            p = self.driver.find_element_by_xpath("//p")
            print link1.text, link2.text
            # 导入需要的Python包
            from selenium.webdriver import ActionChains
            import time
            # 将鼠标悬浮到第一个链接元素上
            ActionChains(self.driver).move_to_element(link1).perform()
            time.sleep(2)
            # 将鼠标从第一个链接元素移动到p元素上
            ActionChains(self.driver).move_to_element(p).perform()
            time.sleep(2)
            # 将鼠标悬浮到第二个链接元素上
            ActionChains(self.driver).move_to_element(link1).perform()
            time.sleep(2)
            # 将鼠标从第二个链接元素移动到p元素上
            ActionChains(self.driver).move_to_element(p).perform()
            time.sleep(2)
    
    
        def tearDown(self):
            # 退出IE浏览器
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()
  • 相关阅读:
    迭代器,生成器,列表推倒式
    内置函数
    递归与二分算法
    装饰器
    函数进阶
    函数
    MLP神经网络 隐含层节点数的设置】如何设置神经网络隐藏层 的神经元个数
    用CNN及MLP等方法识别minist数据集
    ubuntu 安装Pangolin 过程
    ubuntu16.04 + Kdevelop + ROS开发和创建catkin_ws工作空间
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/8709478.html
Copyright © 2011-2022 走看看