Home > Automation Testing > Use of actions class to perform mouse operation in selenium

Use of actions class to perform mouse operation in selenium

This post was most recently updated on June 14th, 2019

In Selenium Action class is used to perform

  1. drag and drop operation
  2. move any element
  3. Press composite key
  4. hover on element

Click action related function with their uses

Click and Move Actions Their uses
click() Perform left click action on current mouse position.
click(WebElement target) Perform left click action on center of given web element.
contextClick() Perform right/context click action on current mouse position.
contextClick(WebElement target) Perform right/context click action on center of given web element.
doubleClick() Perform double left click action on current mouse position.
doubleClick(WebElement target) Perform double left click action on center of given web element.
clickAndHold() Perform left click action on current mouse position and left mouse button not released.
clickAndHold(WebElement target) Perform left click action on center of given web element and left mouse button not released.
moveByOffset(int xOffset, int yOffset) Move mouse cursor from current location to given location.
moveToElement(WebElement target) Move mouse cursor from current location to mid of targeted element.
moveToElement(WebElement target, int xOffset, int yOffset) Move mouse cursor from given element’s top-left corner to given offset location.

 

Selenium code to perform click using click(WebElement target) function.

 

Selenium code to perform click using moveToElement(WebElement target) and click() function.

 

Use of contextClick() and contextClick(WebElement target)

 

Use of moveToElement(WebElement target, int xOffset, int yOffset) and release()

Selenium Tutorial >>

This Article is TAGGED in , , . BOOKMARK THE permalink.

Avatar photo
Neeraj Vishwakarma
Senior QA Engineer Skills: Automation Testing, Manual Testing, STLC, Java, Selenium Webdriver, Protractor, Database Testing.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">