Open In App

Special Keys in Selenium Python

Selenium’s Python Module is built to perform automated testing with Python. Special Keys is an exclusive feature of Selenium in python, that allows pressing keys through keyboard such as ctrl+f, or shift+c+v, etc. class selenium.webdriver.common.keys.Keys handles all Keys in Selenium Python. It contains huge number of key methods one can use in Selenium Python.
 

How to use Special Keys in Selenium Python

To demonstrate, Special Keys, let’s use key_up method of Action Chains in Selenium Python. This bot visits https://www.geeksforgeeks.org/ and press ctrl+f to open search bar.
Program – 
 




# import webdriver
from selenium import webdriver
 
# import Action chains
from selenium.webdriver.common.action_chains import ActionChains
 
# import KEYS
from selenium.webdriver.common.keys import Keys
 
# create webdriver object
driver = webdriver.Firefox()
 
# get geeksforgeeks.org
 
# create action chain object
action = ActionChains(driver)
 
# perform the operation
action.key_down(Keys.CONTROL).send_keys('F').key_up(Keys.CONTROL).perform()

Output – 
 

 

Special Keys

Various keys that can be used in Selenium Python are – 
 

ADD ALT ARROW_DOWN
ARROW_LEFT ARROW_RIGHT ARROW_UP
BACKSPACE BACK_SPACE CANCEL
CLEAR COMMAND CONTROL
DECIMAL DELETE DIVIDE
DOWN END ENTER
EQUALS ESCAPE F1
F10 F11 F12
F2 F3 F4
F5 F6 F7
F8 F9 HELP
HOME INSERT LEFT
LEFT_ALT LEFT_CONTROL LEFT_SHIFT
META MULTIPLY NULL
NUMPAD0 NUMPAD1 NUMPAD2
NUMPAD3 NUMPAD4 NUMPAD5
NUMPAD6 NUMPAD7 NUMPAD8
NUMPAD9 PAGE_DOWN PAGE_UP
PAUSE RETURN RIGHT
SEMICOLON SEPARATOR SHIFT
SPACE SUBTRACT TAB

 

Article Tags :