Skip to content
Related Articles

Related Articles

Special Keys in Selenium Python
  • Last Updated : 15 May, 2020
GeeksforGeeks - Summer Carnival Banner

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 –




# 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()

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

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :