• WEB自动化_键盘事件(输入内容、全选、退格、回车、删除等)


    1、案例

    from selenium.webdriver.common.keys import Keys
    from selenium import webdriver
    
    # 创建浏览器驱动对象
    driver = webdriver.Chrome(r"D:\chromedriver\chromedriver_win32-V103.0.5060.53\chromedriver.exe")
    # 访问网址
    driver.get("http://www.baidu.com")
    
    # 在文本框输入内容
    ele = driver.find_element_by_id("kw")
    ele.send_keys("selenium")
    
    # 全选
    ele.send_keys(Keys.CONTROL, "a")
    
    # 删除
    ele.send_keys(Keys.DELETE)
    
    # 回车键
    ele.send_keys(Keys.ENTER)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    2、更多键盘事件,进入 Keys.py 方法可见。

    """
    The Keys implementation.
    """
    
    from __future__ import unicode_literals
    
    
    class Keys(object):
        """
        Set of special keys codes.
        """
    
        NULL = '\ue000'
        CANCEL = '\ue001'  # ^break
        HELP = '\ue002'
        BACKSPACE = '\ue003'
        BACK_SPACE = BACKSPACE
        TAB = '\ue004'
        CLEAR = '\ue005'
        RETURN = '\ue006'
        ENTER = '\ue007'
        SHIFT = '\ue008'
        LEFT_SHIFT = SHIFT
        CONTROL = '\ue009'
        LEFT_CONTROL = CONTROL
        ALT = '\ue00a'
        LEFT_ALT = ALT
        PAUSE = '\ue00b'
        ESCAPE = '\ue00c'
        SPACE = '\ue00d'
        PAGE_UP = '\ue00e'
        PAGE_DOWN = '\ue00f'
        END = '\ue010'
        HOME = '\ue011'
        LEFT = '\ue012'
        ARROW_LEFT = LEFT
        UP = '\ue013'
        ARROW_UP = UP
        RIGHT = '\ue014'
        ARROW_RIGHT = RIGHT
        DOWN = '\ue015'
        ARROW_DOWN = DOWN
        INSERT = '\ue016'
        DELETE = '\ue017'
        SEMICOLON = '\ue018'
        EQUALS = '\ue019'
    
        NUMPAD0 = '\ue01a'  # number pad keys
        NUMPAD1 = '\ue01b'
        NUMPAD2 = '\ue01c'
        NUMPAD3 = '\ue01d'
        NUMPAD4 = '\ue01e'
        NUMPAD5 = '\ue01f'
        NUMPAD6 = '\ue020'
        NUMPAD7 = '\ue021'
        NUMPAD8 = '\ue022'
        NUMPAD9 = '\ue023'
        MULTIPLY = '\ue024'
        ADD = '\ue025'
        SEPARATOR = '\ue026'
        SUBTRACT = '\ue027'
        DECIMAL = '\ue028'
        DIVIDE = '\ue029'
    
        F1 = '\ue031'  # function  keys
        F2 = '\ue032'
        F3 = '\ue033'
        F4 = '\ue034'
        F5 = '\ue035'
        F6 = '\ue036'
        F7 = '\ue037'
        F8 = '\ue038'
        F9 = '\ue039'
        F10 = '\ue03a'
        F11 = '\ue03b'
        F12 = '\ue03c'
    
        META = '\ue03d'
        COMMAND = '\ue03d'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
  • 相关阅读:
    tf.sparse
    常用函数(睡眠函数、函数耗时)
    utf8&ascii
    【0121】建立与postgres后端的连接(2)
    ssm手机销售网站的设计与实现毕业设计-附源码
    Bridge Champ与Ignis公链:探索Web3游戏的新未来
    双非渣本,奋斗3年,阿里四面终拿Offer,定级p6
    华为机试真题 Java 实现【拼接URL】
    free marker /spring boot
    微服务 高可用
  • 原文地址:https://blog.csdn.net/weixin_44801980/article/details/125446366