Open In App
Related Articles

Special Keys in Selenium Python

Improve Article
Improve
Save Article
Save
Like Article
Like

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 – 
 

Python3




# 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 – 
 

action-chain-method-Selelnium-python

 

Special Keys

Various keys that can be used in Selenium Python are – 
 

ADDALTARROW_DOWN
ARROW_LEFTARROW_RIGHTARROW_UP
BACKSPACEBACK_SPACECANCEL
CLEARCOMMANDCONTROL
DECIMALDELETEDIVIDE
DOWNENDENTER
EQUALSESCAPEF1
F10F11F12
F2F3F4
F5F6F7
F8F9HELP
HOMEINSERTLEFT
LEFT_ALTLEFT_CONTROLLEFT_SHIFT
METAMULTIPLYNULL
NUMPAD0NUMPAD1NUMPAD2
NUMPAD3NUMPAD4NUMPAD5
NUMPAD6NUMPAD7NUMPAD8
NUMPAD9PAGE_DOWNPAGE_UP
PAUSERETURNRIGHT
SEMICOLONSEPARATORSHIFT
SPACESUBTRACTTAB

 

Last Updated : 23 Aug, 2021
Like Article
Save Article
Similar Reads
Related Tutorials