Wednesday, July 3, 2024
HomeLanguagesPythonSpecial Keys in Selenium Python

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.neveropen.co.za/ 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 neveropen.co.za
 
# 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 – 
 

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

 

Dominic Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments