selenium中send_keys()模拟按键输入的keys类属性列表

keys列表

#断开键

NULL = '\ue000'         # 空键
CANCEL = '\ue001'       # Cancel键,相当于ESC键
HELP = '\ue002'         # Help键
BACKSPACE = '\ue003'    # BackSpace退格键
BACK_SPACE = BACKSPACE  # BackSpace退格键
TAB = '\ue004'          # Tab键
CLEAR = '\ue005'        # 关闭NumLock的5键
RETURN = '\ue006'       # Return回车键(Mac)
ENTER = '\ue007'        # Enter回车键
SHIFT = '\ue008'        # Shift键
LEFT_SHIFT = SHIFT      # Shift键
CONTROL = '\ue009'      # Ctrl键
LEFT_CONTROL = CONTROL  # Ctrl键
ALT = '\ue00a'          # Alt键
LEFT_ALT = ALT          # Alt键
PAUSE = '\ue00b'        # Pause键
ESCAPE = '\ue00c'       # ESC键
SPACE = '\ue00d'        # 空格键
PAGE_UP = '\ue00e'      # PgUp键
PAGE_DOWN = '\ue00f'    # PgDn键
END = '\ue010'          # End键
HOME = '\ue011'         # Home键
LEFT = '\ue012'         # ← 键
ARROW_LEFT = LEFT       # ← 键
UP = '\ue013'           # ↑ 键
ARROW_UP = UP           # ↑ 键
RIGHT = '\ue014'        # → 键
ARROW_RIGHT = RIGHT     # → 键
DOWN = '\ue015'         # ↓ 键
ARROW_DOWN = DOWN       # ↓ 键
INSERT = '\ue016'       # Insert键
DELETE = '\ue017'       # Delete键
SEMICOLON = '\ue018'    # ; 键
EQUALS = '\ue019'       # = 键




#数字键
# 数字0到9键
NUMPAD0 = '\ue01a'
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'
F2 = '\ue032'
F3 = '\ue033'
F4 = '\ue034'
F5 = '\ue035'
F6 = '\ue036'
F7 = '\ue037'
F8 = '\ue038'
F9 = '\ue039'
F10 = '\ue03a'
F11 = '\ue03b'
F12 = '\ue03c'

META = '\ue03d'     # '命令⌘’键(Mac),⊞键(Windows)
COMMAND = '\ue03d'  # Command键(Mac系统)



from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
import pytest
from selenium.webdriver.common.keys import Keys


class TestActionChians():
    def setup(self):
        self.drive = webdriver.Chrome()
        self.drive.implicitly_wait(3)



    def test_case_label(self):
        #实现操作为: 在输入框中输入username然后空格在输入tom后,再点击一个backspace键删除一个m
        #通过action里面的send_keys来实现
        self.drive.get("https://sahitest.com/demo/label.htm")
        ele = self.drive.find_element(By.XPATH,'/html/body/label[1]/input')
        ele.click()
        action = ActionChains(self.drive)
        # action.send_keys("username")
        action.send_keys(Keys.SPACE).pause(1) #pasuse(1) 等待1秒
        action.send_keys("TOM").pause(1)
        action.send_keys(Keys.BACK_SPACE).perform()

        sleep(2)

你可能感兴趣的:(GUI自动化,软件测试)