Action Chain Methods in Selenium Python
One can perform a huge number of operations using Action chains such as click, right-click, etc. Here is a list of important methods used in Action chains.
.math-table {
border-collapse: collapse;
width: 100%;
}
.math-table td {
border: 1px solid #5fb962;
text-align: left !important;
padding: 8px;
}
.math-table th {
border: 1px solid #5fb962;
padding: 8px;
}
.math-table tr>th{
background-color: #c6ebd9;
vertical-align: middle;
}
.math-table tr:nth-child(odd) {
background-color: #ffffff;
}
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. |
Action Chains in Selenium Python
Selenium’s Python Module is built to perform automated testing with Python. ActionChains are a way to automate low-level interactions such as mouse movements, mouse button actions, keypress, and context menu interactions. This is useful for doing more complex actions like hover over and drag and drop. Action chain methods are used by advanced scripts where we need to drag an element, click an element, This article revolves around how to manipulate DOM using Action Chains in Selenium. We have covered all the methods with examples int detail. ActionChains are implemented with the help of a action chain object which stores the actions in a queue and when perform() is called, performs the queued operations.