I would like to know the difference between Action
and Actions
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.
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.
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.
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
.
In the below image, if we mouse hover the keyword Action
, the violet colored I
indicates that Action
is an interface.
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
.
In the below image, if we mouse hover the keyword Actions
, the green colored C
indicates that Actions
is a Class.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With