Module selenium.webdriver.common.action_chains. Each method queues an action
and returns the chain, so calls can be chained; nothing happens until
perform().
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
ActionChains(driver).move_to_element(menu).click(item).perform()
ActionChains(driver).key_down(Keys.CONTROL).send_keys("a").key_up(Keys.CONTROL).perform()| Method | Description | Usage |
|---|---|---|
perform |
Runs all queued actions. | actions.perform() |
reset_actions |
Clears queued actions and releases held keys and buttons. | actions.reset_actions() |
click |
Clicks an element, or the current mouse position if none is given. | actions.click(button) |
click_and_hold |
Presses the left button down on an element. | actions.click_and_hold(slider) |
context_click |
Right-clicks an element. | actions.context_click(row) |
double_click |
Double-clicks an element. | actions.double_click(cell) |
release |
Releases the held mouse button. | actions.release() |
drag_and_drop |
Drags source onto target. |
actions.drag_and_drop(card, column) |
drag_and_drop_by_offset |
Drags source by an x/y offset. |
actions.drag_and_drop_by_offset(handle, 100, 0) |
move_to_element |
Moves the mouse to the centre of an element. | actions.move_to_element(menu) |
move_to_element_with_offset |
Moves to an offset from the element's centre (Selenium 4 changed this from the top-left corner). | actions.move_to_element_with_offset(canvas, 10, -5) |
move_by_offset |
Moves the mouse by an offset from where it is. | actions.move_by_offset(20, 0) |
key_down |
Presses a modifier key (Control, Alt, Shift) without releasing it. | actions.key_down(Keys.SHIFT) |
key_up |
Releases a modifier key. | actions.key_up(Keys.SHIFT) |
send_keys |
Types into the focused element. | actions.send_keys("hello") |
send_keys_to_element |
Clicks an element, then types into it. | actions.send_keys_to_element(field, "hello") |
scroll_to_element |
Scrolls until the element is in view. | actions.scroll_to_element(footer) |
scroll_by_amount |
Scrolls the page by a delta. | actions.scroll_by_amount(0, 500) |
scroll_from_origin |
Scrolls from an element or point, e.g. inside a scrollable box. | actions.scroll_from_origin(ScrollOrigin.from_element(box), 0, 200) |
pause |
Waits between queued actions. | actions.pause(0.5) |
ScrollOrigin is in selenium.webdriver.common.actions.wheel_input.