Keys列表
Keys值 | 按键 |
---|
NULL | 空键 |
CANCEL | Cancel键,相当于ESC键 |
HELP | Help键 |
BACKSPACE/BACK_SPACE | BackSpace退格键 |
TAB | Tab键 |
ENTER | Enter回车键 |
SHIFT/LEFT_SHIFT | Shift键 |
CONTROL/LEFT_CONTROL | Ctrl键 |
ALT | Alt键 |
PAUSE | Pause键 |
ESCAPE | Esc键 |
SPACE | 空格键 |
PAGE_UP | PgUp键 |
PAGE_DOWN | PgDn键 |
END | End键 |
HOME | Home键 |
LEFT/ARROW_LEFT | ← 键 |
UP/ARROW_UP | ↑ 键 |
RIGHT/ARROW_RIGHT | → 键 |
UDOWN/ARROW_DOWN | ↓ 键 |
INSERT | Insert键 |
DELETE | Delete键 |
SEMICOLON | ; 键 |
EQUALS | = 键 |
NUMPAD0,…NUMPAD9 | 数字0-9 |
MULTIPLY | * 键 |
ADD | + 键 |
SEPARATOR | , 键 |
SUBTRACT | - 键 |
DECIMAL | . 键 |
DIVIDE | / 键 |
F1,…F9 | F1-F9键 |
META | 命令键(Mac:⌘键, Windows:⊞键) |
COMMAND | Command键(Mac系统) |
实例
from selenium import webdriver
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.chrome.service import Service
option = webdriver.ChromeOptions()
option.add_experimental_option("prefs", {
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing.enabled": True,
"credentials_enable_service": False,
"profile.password_manager_enabled": False
})
option.add_experimental_option('excludeSwitches', ['enable-automation'])
driver = webdriver.Chrome(service=Service("../config/chromedriver.exe"), options=option)
driver.maximize_window()
driver.implicitly_wait(10)
driver.get('https://www.baidu.com')
ele = driver.find_element('xpath', '//input[@id="kw"]')
ele.click()
action = ActionChains(driver)
action.send_keys(Keys.NUMPAD0).perform()
action.send_keys(Keys.SPACE).perform()
action.send_keys(1).perform()
action.send_keys(Keys.LEFT).perform()
action.send_keys(Keys.BACKSPACE).perform()