Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Action and Actions in Selenium?

Tags:

selenium

I would like to know the difference between Action and Actions in Selenium

like image 522
Akhilesh Keshari Avatar asked Aug 03 '17 18:08

Akhilesh Keshari


People also ask

What is actions and action in Selenium?

Actions class is an ability provided by Selenium for handling keyboard and mouse events. In Selenium WebDriver, handling these events includes operations such as drag and drop, clicking on multiple elements with the control key, among others. These operations are performed using the advanced user interactions API.

What is difference between build () and perform () in Selenium?

Difference between build() and perform() in SeleniumThe build() command of action interface generates a composite action that contains all the actions gathered which are ready to be performed. The perform() command is used to perform a sequence of actions without calling build() first.

What is Perform () in action class?

perform(); Build(). perform() is used to compile and execute the actions class. Use the different methods under the actions class to perform various operations like click(), drag and drop and so on.


2 Answers

Action:

In Selenium, Action is an interface which represents a single user-interaction action. It is defined in org.openqa.selenium.interactions. It contains one of the most widely used method perform(). You can find more about the implementing Classes and Methods in this link.

Action Example:

In the below image, if we mouse hover the keyword Action, the violet colored I indicates that Action is an interface.

InterfaceAction


Actions:

In Selenium, Actions is a Class. It is defined in org.openqa.selenium.interactions. This is the user-facing API for emulating complex user gestures. Actions Class implements the builder pattern, which can build a CompositeAction containing all actions specified by the method calls. You can find more about the Method Summary in this link.

Actions Example:

In the below image, if we mouse hover the keyword Actions, the green colored C indicates that Actions is a Class.

enter image description here

like image 162
undetected Selenium Avatar answered Sep 19 '22 12:09

undetected Selenium


Action is an interface :

public interface Action

Action Interface representing a single user-interaction action.

VS

Actions is a Class that extends from Object

public class Actions
extends java.lang.Object

The user-facing API for emulating complex user gestures. Use this class rather than using the Keyboard or Mouse directly.

Edit:

Thanks to @mrfreester pointed out. You can string a bunch of actions together using Actions, and then once you call build() it will store that set of steps as an Action. Once you have an Action, you can call perform() to execute that set of steps.

like image 36
OLIVER.KOO Avatar answered Sep 20 '22 12:09

OLIVER.KOO