Selenium - Mouse Actions

Listed below are some of the key mouse actions that one would come across in most of the applications -

  • Click − Performs a Click. We can also perform a click based on coordinates.

  • contextClick − Performs a context click/right-click on an element or based on the coordinates

  • doubleClick − Performs a double-click on the webelement or based on the coordinates. If left empty, it performs double-click on the current location.

  • mouseDown − Performs a mouse-down action on an element or based on coordinates.

  • mouseMove − Performs a mouse-move action on an element or based on coordinates.

  • mouseUp − Releases the mouse usually followed by mouse-down and acts based on co-ordinates.

Here are the syntax to call mouse actions using Selenium WebDriver -

void click(WebElement onElement)
void contextClick(WebElement onElement)
void doubleClick(WebElement onElement)
void mouseDown(WebElement onElement)
void mouseUp(WebElement onElement)
void mouseMove(WebElement toElement)
void mouseMove(WebElement toElement, long xOffset, long yOffset)