Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mouse actions in Java
// Clicks in the middle of the given element.
click(WebElement target);
// Clicks (without releasing) at the current mouse location.
clickAndHold(WebElement target);
// Performs a context-click at middle of the given element. First performs a mouseMove to the location of the element.
contextClick(WebElement target);
// Performs a double-click at middle of the given element.
doubleClick(WebElement target);
// A convenience method that performs click-and-hold at the location of the source element,
// moves to the location of the target element, then releases the mouse.
dragAndDrop(WebElement source, WebElement target);
// A convenience method that performs click-and-hold at the location of the source element,
// moves by a given offset, then releases the mouse.
dragAndDrop(WebElement source, int xOffset, int yOffset);
// Moves the mouse to the middle of the element.
moveToElement(WebElement target);
// Moves the mouse to an offset from the top-left corner of the element.
moveToElement(WebElement source, int xOffset, int yOffset);
// Releases the depressed left mouse button at the current mouse location.
release();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment