Action Chains & Special Keys
On this page you'll learn about Action Chains, special keys, and special key combinations
Introduction
Selenium Action Chains allow you to simulate keyboard presses of any key on your keyboard, including "special keys" like ctrl, cmd, etc. Simple Selenium has an easy-to-use Action Chains class built into the WebDriver class, which you'll learn how to use on this page.
Simple Selenium Action Chains
Using Simple Selenium Action Chains is easy, and similar to normal Selenium:
#Start chrome webdriver with custom options
driver=SimpleSelenium("chrome",save_profile=True,profile_name="myAwesomeProfile",save_logs_in_file=True,maximized=True)
#Visit Google
driver.visit("https://google.com")
#Locate the main search bar
textArea=driver.by_tag("textarea")
#Use ActionChains to click the search bar
thisActionChain=driver.actionChains.click(textArea).press_key("t").press_key("e").press_key("s").press_key("t").press_key("enter")
thisActionChain.perform() #Executes all actions in the chain (click search bar, type "test", click enter). This is not the optimal way to type text in an input, but just an example for Action Chains
#You can add as many actions as you like onto an action chain, they get executed in order.Executing Special Key Commands (eg. ctrl-c, ctrl-v)
When building automation scripts, it's sometimes necessary to execute special key commands like ctrl-c, ctrl-v (cop & paste). In Simple Selenium, you can do this with:
You can add as many keys as you would like to special_key_combo. Each key will be pressed one-by-one, then released one-by-one in order.
List of Simple Selenium Action Chains Methods
Below, is a list of every Simple Selenium Action Chains method, with examples on how to use them.
Press Key
You can use press_key to press & release any key on the keyboard. A list of all "special key" aliases can be found at the bottom of this page:
Key Down
You can use key_down to press but not release any key on the keyboard. A list of all "special key" aliases can be found at the bottom of this page:
Key Up
You can use key_up to release any key on the keyboard that is currently being pressed by key_down. A list of all "special key" aliases can be found at the bottom of this page:
Click
Performs a click, either on or not on a target element:
Click & Hold
Performs a click but doesn't release the mouse button, either on or not on a target element:
Release Click Hold
Releases click hold, either on or not on a target element:
Context/Right Click
Performs a right click, either on or not on a target element:
Double Click
Performs a double click, either on or not on a target element:
Drag & Drop
Performs a drag & drop:
Drag & Drop By Offset
Performs a drag & drop but uses an offset in pixels away from starting position instead of a target "drop-on" element:
Move Mouse By Offset
Moves the mouse by x, y pixels offset:
Move Mouse To Element
Moves the mouse to an element:
Move Mouse To Element With Offset
Moves the mouse to an element with x, y offset in pixels:
Reset Actions
Resets all Action Chains actions:
Scroll By Amount
Scrolls focused window by x, y pixels:
Scroll To Element
Scrolls focused window until target element is in view:
Pause
Pause in the middle of action chain for x seconds:
Perform
Perform the entire action chain from first action -> last action:
Special Key Aliases
Below, is a list of all "special key" aliases you can use while executing functions like .press_key():
Last updated