ActionChains

Syntax

from selenium import webdriver 
from selenium.webdriver.common.action_chains import ActionChains
 
driver = webdriver.Chrome()
 
# create action chain object
action = ActionChains(driver)
# element to be clicked on
element = driver.find_element(By.ID, "submit")
# using the action object
action.click(on_element=element).perform()

# drag and drop
action.drag_and_drop(source_element, target_element).perform() 

Action Methods

Method

Description

click

Clicks an element.

click_and_hold

Holds down the left mouse button on an element.

context_click

Performs a context-click (right click) on an element.

double_click

Double-clicks an element.

drag_and_drop

Holds down the left mouse button on the source element, then moves to the target element and releases the mouse button.

drag_and_drop_by_offset

Holds down the left mouse button on the source element, then moves to the target offset and releases the mouse button.

key_down

Sends a key press only, without releasing it.

key_up

Releases a modifier key.

move_by_offset

Moving the mouse to an offset from current mouse position.

move_to_element

Moving the mouse to the middle of an element.

move_to_element_with_offset

Move the mouse by an offset of the specified element, Offsets are relative to the top-left corner of the element.

perform

Performs all stored actions.

pause

Pause all inputs for the specified duration in seconds

release

Releasing a held mouse button on an element.

reset_actions

Clears actions that are already stored locally and on the remote end

send_keys

Sends keys to current focused element.

Updated on