Special Keys in Selenium Python

Selenium’s Python Module is built to perform automated testing with Python. Special Keys is an exclusive feature of Seleium 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, lett’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 –

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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 oepration
action.key_down(Keys.CONTROL).send_keys('F').key_up(Keys.CONTROL).perform()

chevron_right


Output –
action-chain-method-Selelnium-python

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
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.