• selenium-模拟鼠标


    需要导入的包:

    from selenium.webdriver import ActionChains

    一、模拟鼠标右键

    ActionChains(self.driver).context_click(xxx).perform()  

    # coding=UTF-8
    #19.模拟鼠标右键
    import sys
    reload(sys)
    sys.setdefaultencoding('utf8')
    from selenium import webdriver
    import unittest
    import time
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver import ActionChains
    
    class Case18(unittest.TestCase):
    
        def setUp(self):
            self.driver = webdriver.Chrome()
    
        def test_simulateASingleKey(self):
            url = "https://www.sogou.com"
            self.driver.get(url)
            element = self.driver.find_element_by_id("query")
            element.send_keys("selenium")
            time.sleep(2)
            element.send_keys(Keys.CONTROL, 'a')  # c trl+a 全选输入框内容
            time.sleep(2)
            element.send_keys(Keys.CONTROL,'x') # ctrl+x 剪切输入框内容
            time.sleep(2)
            ActionChains(self.driver).context_click(element).perform() # 鼠标右击单击
            time.sleep(2)
            ActionChains(self.driver).send_keys('P').perform() #发送黏贴命令,字符P代表黏贴 (只支持IE浏览器)
            time.sleep(2)
    
        def tearDown(self):
            self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()

    二、模拟鼠标左键按下与释放

    ActionChains(self.driver).click_and_hold(xxx).perform() ——在xxx元素上执行按下鼠标左键并保持
    ActionChains(self.driver).release(xxx).perform() ——在xxx元素上释放一直按下的鼠标左键

    三、保持鼠标悬停在某个元素上

    ActionChains(self.driver).move_to_element(xxx).perform() ——将鼠标悬浮到xxx元素上

  • 相关阅读:
    thinkphp中插入ueditor编辑器的代码
    编辑器
    php中上传图片,原生代码
    thinkphp中上传图片以及制成缩略图
    https://www.oschina.net/project/lang/19/java
    js中各种弹窗
    MYSQL数据库中中文乱码问题
    关于对CSS中超链接那部分的设置
    Collectors.groupingBy应用
    定时器算法
  • 原文地址:https://www.cnblogs.com/erchun/p/11800806.html
Copyright © 2020-2023  润新知