Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

What is Action Class in Selenium & It’s Applications?

Updated on 18 November, 2022

7.14K+ views
7 min read

Action Class in Selenium is a built-in feature offered by selenium for managing keyboard and mouse events. It can manage multiple operations and events such as control key, drag and drop, and many more. The Action Class’s operations are implemented using the advanced user interaction API feature of the Selenium Webdriver. 

Check out our free courses to get an edge over the competition.

Commonly used Keyboard and Mouse Events

Special keyboard and mouse events are handled using the Advanced User Interactions API. This API contains the Action and the Actions class that are required while executing these events. Given below are the commonly used keyboard and mouse events provided in the Action class. 

Method Description
Click And Hold() To click without releasing at the current mouse location.
context-click() Performs a context-click(Right-click mouse action) at the current mouse location 
doubleClick() Performs a double-click action at the current mouse location
drag and drop(source, target)

Performs click-and-hold operation at the source element location, then moves to the target element location and releases the mouse.

Parameters:

source-element to emulate button-down events.

Target-element to move and release the mouse  

dragAnd DropBy(source, x-offset, y-offset) 

Performs click-and-hold at the source element location, moves by a specified offset and then releases the mouse.

Parameters:

source-element to emulate button-down events.

xOffset- to specify horizontal move offset.

yOffset- to specify vertical move offset.

keyDown(modifier_key)

Performs the modifier keypress event. Does not release the modifier key with subsequent interactions assuming that it is pressed.

Parameters:

modifier_key to represent any of the modifier keys, such as Keys.SHIFT, Keys.ALT, or Keys.CONTROL.

key Up(modifier_key)

Performs a key release.

Parameters:

modifier_key to represent any of the modifier keys, such as Keys.SHIFT, Keys.ALT or Keys.CONTROL.

moveByOffset(x-offset, y-offset)

Moves the mouse from the current position by the specified offset. 

Parameters:

x-offset to specify the horizontal offset. A negative value means the mouse is moving to the left.

y-offset to specify the vertical offset. A negative value means the mouse is moving downwards.

moveToElement(toElement)

Moves the mouse from the middle to the middle of the element.

Parameters:

element to represent the element to move to.

release() Releases the pressed mouse left mouse button at the current mouse location.
sendKeys(onElement, charsequence)

Sends a series of keystrokes on to the element.

Parameters:

Element to represent the element that will get the keystrokes, usually a text field.

Char sequence- any string value to represent the sequence of keystrokes that is sent. 

Examples of Application of the Selenium Action Class

1. Import Action and the Action class.

import org.open a.selenium.interactions.Action;

import org.open a.selenium.interactions.Actions;

Check out upGrad’s Full Stack Development Bootcamp (JS/MERN)

2. Instantiate a new Actions object

Actions builder = new Actions(driver);

3. Instantiate an Action using the Action object in the previous step

Action mouseOverHome = builder

.moveToElement(link_Home)

.build();

Here, we are using the moveToElement() method to perform a mouse-over the Home link. The build() is always the final method to ensure that all actions are compiled in a single step.

Check out upGrad’s Java Bootcamp.  

4. Use the perform method while executing the Action object we declared in the previous step.

Syntax:

mouseOverHome.perform();

Example 2:

Let us take another example where the Action class is used to implement the textbox’s Autocomplete feature.

To do this manually, we press the shift key, type the text that must be entered in uppercase and then let go of the shift key. Put, Shift + alphabet keys are pressed together.

To mimic the same operation through automation script, the Actions Class method is utilized. 

1. Import-Package

Action and Actions class exist in the org.openqa.selenium.interactions package of the Web Driver API. To use these you must import packages:

org.openqa.selenium.interactions.Action;

org.openqa.selenium.interactions.Actions;

2. Instantiate the Action class

It would help if you created an object of the Actions class to invoke its methods. So, we instantiate the Actions class and use the WebDriver object to initiate the class. The syntax is:

Actions actions = new Actions (webdriver object);

3. Generate a sequence of actions

In this example, the sequence of steps to perform multiple actions are:

  • Press the Shift key
  • Send the desired text
  • Release the Shift key

To perform these actions, the Action class has methods such as:

  • keyDown method to press the Shift key.
  • sendKeys method to send the desired text.
  • The keyUp method releases the Shift key.
  • The keyDown acts as a modifier key press to focus on an element while the keyUp method releases a modifier key pressed. 

A modifier key changes the action of another key when both the keys are pressed simultaneously. E.g., Shift, Alt and Ctrl.

A sequence of actions is generated but these actions are performed on a webElement. The steps for this are:

WebElement element = driver.findElement;

actions.keyDown(element, Keys, Shift);

action.sendKeys(“TexttoBeConvertAndSendInUpperCase);

actions.keyUp(Keys.Shift);

The important thing to observe here is that if you happen to hover around any Action class method, an Actions class object will be returned

4. Build the actions sequence

You can build the actions sequence through the build() method of the Actions class. This method generates the entire set of actions that are ready to be performed. The syntax is:

Action action = actions.build();

The build() method returns an object of type Action that represents a composite action built from a sequence of multiple actions invoked by method calls.

5. Perform action sequences

The last step in executing the Action class is performing the actions sequence through the perform() method of the Action interface. The syntax is:

action.perform();

The above-given steps must be executed to leverage all of the Actions class methods and perform different user actions using the keyboard and mouse.

Learn Software Development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

What Next?

If you’re interested to learn more about Full-Stack Software development, check out upGrad & IIIT-B’s Executive PG Program Full-stack Software Development which is designed for working professionals and offers 500+ hours of rigorous training, 9+ projects, and assignments, IIIT-B Alumni status, practical hands-on capstone projects & job assistance with top firms.

Frequently Asked Questions (FAQs)

1. What is action class in Selenium?

An action class is a class that describes an action, or a series of actions, that you can perform on a web element. We identify the elements we want to perform actions on by locators. Action classes are defined by the two-character combination of a public static class level modifier and an Action suffix (i.e. Action, KeyAction, PageAction, etc.). The public static modifier enables us to expose the class as a class that can be instantiated. The Action suffix denotes the type of action being performed. The Action suffix class is also parameterized. The parameter is the element name of the action. For example, if we want to perform an action on a text field, we would use the parameter textfield.

2. What are the uses of Selenium?

Selenium is a very powerful portable software testing tool (selenium software testing tool), which is used to record and playback the user actions on a web page. It is used to test the functional and non-functional requirements of a web application on any web browser. It is implemented in Java and has a very simple API. It supports web applications testing in all the major web browsers like Firefox, Chrome, Internet Explorer, Safari etc.

3. How to learn Selenium in Java?

Selenium is a tool that allows you to write automated tests in a number of programming languages. Tests are written using web driver. You can use it to test your web application based on the following programming languages: Java, C#, Python and PHP. Actually, many developers feel that it is not so necessary to learn Selenium Java API. Selenium WebDriver is the right choice to find elements on the page and perform actions with them. It is possible to implement tests in many programming languages, but if you need to write tests in Java, then Selenium WebDriver is the best choice. Another method to learn Selenium in Java is using Selenium IDE, also known as Selenium RC. Browsers support for this tool is not so good as we know, only Firefox and Chrome are supported. But, the IDE can help you to rapidly design and execute Selenium test cases, record and playback test case, auto generate test cases, etc.

RELATED PROGRAMS