Selenium Webdriver action chains (Java)

Selenium Webdriver action chains (Java)

With Selenium Webdriver it is possible to create a chain of actions to implemented with one line of code. This is done with the Actions class. Actions is implemented with an instance of the WebDriver and can be used for such actions like click and drag or moving the mouse to hover over an element before interacting with it. Below is a script showing an example of action chains:

Actions actions = new Actions(driver);
actions.moveByOffset(0, 100).click().build().perform();

The above code will cause the driver to click on the page 100 pixels above its current position. As can be seen, action chains require you to build and then perform the execution explicitly as opposed to normal Webdriver commands which do it automatically.

Leave a reply

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

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.