zoukankan      html  css  js  c++  java
  • Selenium WebDriver-actionchain模拟鼠标右键操作

    #encoding=utf-8
    import unittest
    import time
    from selenium import webdriver
    from selenium.webdriver import ActionChains
    import win32clipboard as w
    import win32con
    
    # 设置剪切板内容
    def setText(aString):
        w.OpenClipboard()
        w.EmptyClipboard()
        w.SetClipboardData(win32con.CF_UNICODETEXT, aString)
        w.CloseClipboard()
    
    
    class VisitSogouByIE(unittest.TestCase):
    
        def setUp(self):
            #启动IE浏览器
            #self.driver = webdriver.Firefox(executable_path = "e:\geckodriver")
            self.driver = webdriver.Ie(executable_path = "e:\IEDriverServer")
            #仅能ie生效
            
        def test_rigthClickMouse(self):
            url = "http://www.sogou.com"
            # 访问搜狗首页
            self.driver.get(url)
            # 找到搜索输入框
            searchBox = self.driver.find_element_by_id("query")
            # 将焦点切换到搜索输入框
            searchBox.click()
            time.sleep(2)
            # 在搜索输入框上执行一个鼠标右键点击操作
            ActionChains(self.driver).context_click(searchBox).perform()
            # 将“gloryroad”数据设置到剪切板中,相当于执行了复制操作
            setText(u'gloryroad')
            # 发送一个粘贴命令,字符p指代粘贴操作
            ActionChains(self.driver).send_keys('P').perform()
            # 点击搜索按钮
            self.driver.find_element_by_id('stb').click()
            time.sleep(2)
    
    
    
        def tearDown(self):
            # 退出IE浏览器
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()
  • 相关阅读:
    Spark SQL ---一般有用
    idea快捷键
    04.Scala编程实战 ---没看
    03.Scala高级特性 ---没看
    02.Actor编程 ---没看
    01.Scala编程基础 ---没看
    附6、Storm面试题目答疑 ---一般有用
    扩展运算符
    ES6新增数组方法(部分)
    for of 循环
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/8709452.html
Copyright © 2011-2022 走看看