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 |
---|---|
Clicks an element. | |
Holds down the left mouse button on an element. | |
Performs a context-click (right click) on an element. | |
Double-clicks an element. | |
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. |
Sends a key press only, without releasing it. | |
Releases a modifier key. | |
Moving the mouse to an offset from current mouse position. | |
Moving the mouse to the middle of an element. | |
Move the mouse by an offset of the specified element, Offsets are relative to the top-left corner of the element. | |
Performs all stored actions. | |
Pause all inputs for the specified duration in seconds | |
Releasing a held mouse button on an element. | |
Clears actions that are already stored locally and on the remote end | |
Sends keys to current focused element. |