Difference between Action and Actions in Selenium

0 votes
What are the differences between Action and Actions in Selenium
Apr 9, 2018 in Selenium by kurt_cobain
• 9,390 points

2 answers to this question.

0 votes

Action is an interface :

public interface Action

Action Interface represents a single user-interaction action.

and Actions is a Class that extends Object class

public class Actions
extends java.lang.Object

Use this class rather than using the Keyboard or Mouse directly.

For further understanding, you can refer to the Selenium Training.

answered Apr 9, 2018 by Martin
• 4,320 points
0 votes

 Actions class is based on builder design pattern which builds a composite actions with the aggregation of Selenium WebDriver, where webdriver is only used to identify the presence of web elements on web application

 Action interface is only used to represent the single user interaction i.e to perform the series of action items build by Actions class. 


Let's Assume we want to Sent text in Caps in Text field. We need to Press SHIFT and then send Text and then we will release from SHIFT key.

Performing all the task at a time  using Selenium API we will use Actions class and Action interface.

1) Actions actions = new Actions(webdriver object);

 Since we need to perform all action one by one  like this "actions.

2)  keyDown(element, Keys.SHIFT) + sendKeys(“Text_In_UpperCase”) + keyUp(Keys.SHIFT)".

we can clubbed all action together as below.

 3) actions.keyDown(element, Keys.SHIFT).sendKeys(“Text_In_UpperCase”).keyUp(Keys.SHIFT);

Now,We need to build this sequence using the build() method of Actions class and get the composite action.

4) Action action = actions.build();

Keep in mind that the build method always returns “Action type object”  so  we need to create reference of Action Interface and hold  all builder's Actions.

And finally, perform the actions sequence using perform() method of Action Interface.

5) action.perform();


In short we can use:-

actions.keyDown(element,   Keys.SHIFT).sendKeys(“Text_In_UpperCase”).keyUp(Keys.SHIFT).build().perform();

answered Jun 21, 2019 by virendra

edited Jul 26, 2019
Hi Virendra, can you explain your answer with some example or dummy code?
@Virendra, thanks for sharing the examples and explaining the differences this well. Please look at the other threads also, which you think you can contribute to.

Related Questions In Selenium

0 votes
1 answer

What's the difference between functions getClass() and getAttribute(“class”) in Selenium?

The simple difference is that, getClass() returns ...READ MORE

answered Apr 7, 2018 in Selenium by nsv999
• 5,500 points
0 votes
2 answers
0 votes
1 answer

What is difference between Assert and Verify in Selenium?

Hello, talking about the definition.  Assert: If the assert condition ...READ MORE

answered Dec 31, 2018 in Selenium by Prasad
–1 vote
1 answer

Difference between sleep() and setSpeed() in selenium

Both sleep() and setSpeed() are used to ...READ MORE

answered Feb 13, 2019 in Selenium by Priyaj
• 58,090 points
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
0 votes
1 answer

Basic authentication with Selenium in Internet Explorer 10

My upgrade to Internet Explorer 10 was ...READ MORE

answered Sep 14, 2018 in Selenium by Martin
• 4,320 points
0 votes
1 answer

How can I download the *.jar file from http:// seleniumhq.org using selenium WebDriver?

For Selenium Standalone Server use this: profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/java-archive"); and ...READ MORE

answered Apr 9, 2018 in Selenium by Martin
• 4,320 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP