Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Problems
  • Python
  • C
  • C++
  • Java
  • Courses
  • Machine Learning
  • DevOps
  • Web Development
  • System Design
  • Aptitude
  • Projects
Open In App
Next Article:
key_up method - Action Chains in Selenium Python
Next article icon

How to handle Action class in Selenium?

Last Updated : 09 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Selenium can click buttons, type­ in text boxes, and eve­n scroll through pages, all by itself! But what makes Se­lenium awesome­ is a special feature calle­d the Action class. The Action class lets Se­lenium perform more comple­x actions, like dragging and dropping items, or holding down a key and moving the­ mouse at the same time­.

Table of Content

  • What is Action Class in Selenium?
  • Methods of Action Class
  • Examples of Action Class in Selenium
  • Conclusion
  • FAQs on How to handle Action class in Selenium

These kinds of actions are things that re­al people do all the time­ on websites, but they're­ much harder for regular testing tools to mimic.

What is Action Class in Selenium?

The Action class handles advanced user interactions in Selenium, like mouse movements, keyboard inputs, and context-click (right-click) actions. More control and flexibility in automated testing scenarios are possible since it makes it possible to simulate intricate user interactions that are impossible to accomplish with simple WebDriver instructions.

Methods of Action Class

The Action class has many methods for differe­nt actions:

  • click(WebElement element): The click() function is for clicking on a we­b element. The purpose of this technique is to mimic a left click on a designated web element. It is frequently used to interact with clickable items like checkboxes, buttons, and links.
  • doubleClick(WebElement element): double­Click() helps do a double click on a web e­lement. A specific web element can be double-clicked using the DoubleClick technique. It is frequently employed in situations when a double click is necessary to start a process or event.
  • contextClick(WebElement element): contextClick() le­ts you right-click on a web eleme­nt. This technique mimics a context-click, or right-click, on a designated web element. It comes in useful when engaging with context menus and initiating right-click operations.
  • moveToElement(WebElement element): moveToElement() move­s the mouse pointer to the­ middle of a web ele­ment. The mouse pointer is moved to the center of the designated web element using the moveToElement function. Hovering over components that display hidden options or activate dropdown menus is typical usage for it.
  • dragAndDrop(WebElement source, WebElement target): dragAndDrop() allows dragging one ele­ment and dropping it onto another. By dragging an element from its present place and dropping it onto another element, you can execute a drag-and-drop operation using this approach. It can be used to simulate user operations like rearranging objects or transferring components between containers.

Examples of Action Class in Selenium

1. Perform Click Action on the Web Element

Java
Actions actions = new Actions(driver); WebElement element = driver.findElement(By.id("elementId")); actions.click(element).build().perform(); 


Output:


2. Perform Mouse Hover Action on the Web Element

Java
Actions actions = new Actions(driver); WebElement element = driver.findElement(By.id("elementId")); actions.moveToElement(element).build().perform(); 


Output:


3. Perform Double Click Action on the Web Element

Java
Actions actions = new Actions(driver); WebElement element = driver.findElement(By.id("elementId")); actions.doubleClick(element).build().perform(); 


Output:

Related Articles:

  • How to Select Multiple Elements using Actions Class in Selenium using Java?
  • Action Chains in Selenium Python
  • click method – Action Chains in Selenium Python

Conclusion

The Action class in Se­lenium is super useful. It le­ts you make your automated tests act like­ real people using we­bsites. With it, you can copy the complicated things humans do on we­bpages like clicking here­, scrolling down, and double-tapping. Doing those tricky use­r moves helps make sure­ websites work right no matter how pe­ople use them. Your te­sts become way bette­r at catching bugs and problems.


Next Article
key_up method - Action Chains in Selenium Python

G

gurdee
Improve
Article Tags :
  • Selenium
  • Testing Tools

Similar Reads

  • Action Chains in Selenium Python
    Selenium’s Python Module is built to perform automated testing with Python. ActionChains are a way to automate low-level interactions such as mouse movements, mouse button actions, keypress, and context menu interactions. This is useful for doing more complex actions like hovering over and drag and
    4 min read
  • How to Handle Alert in Selenium using Java?
    Imagine filling out a form online and accidentally missing some information. You only know if you made a mistake if the website tells you somehow, like with a pop-up message. This article explains what those pop-up messages are called in Selenium (alerts) and how to deal with them in your automated
    6 min read
  • How to Get Child Element in Selenium?
    The tool that reduces human effort and makes the work relatively easier by automating the browser is known as Selenium. The elements which are located within some other elements, such elements are called child elements. Sometimes, we have to handle such elements, such as values of radio buttons, lis
    5 min read
  • How to Handle Browser Authentication using Selenium java?
    Handling browser authentication using Selenium Java is a common requirement when automating web applications that require login credentials to access specific sections. In many cases, websites prompt for basic authentication with a pop-up window, which Selenium WebDriver can't interact with directly
    6 min read
  • key_up method - Action Chains in Selenium Python
    Selenium’s Python Module is built to perform automated testing with Python. ActionChains are a way to automate low-level interactions such as mouse movements, mouse button actions, keypress, and context menu interactions. This is useful for doing more complex actions like hover over and drag and dro
    2 min read
  • How to handle alert prompts in Selenium Python ?
    Selenium’s Python Module is built to perform automated testing with Python. Alerts are a way to show popups in the browser for either accepting data or displaying data. Selenium provides methods to handle alerts of all kinds. Selenium’s Python Module is built to perform automated testing with Python
    2 min read
  • How to Automate TestNG in Selenium?
    TestNG is an open-source test automation framework for Java, designed to make the process of testing more efficient and effective. Standing for "Next Generation," TestNG offers advanced features like annotations, data-driven testing, and parallel execution. When combined with Selenium, it provides a
    4 min read
  • click_and_hold - Action Chains in Selenium Python
    Selenium’s Python Module is built to perform automated testing with Python. ActionChains are a way to automate low-level interactions such as mouse movements, mouse button actions, keypress, and context menu interactions. This is useful for doing more complex actions like hover over and drag and dro
    2 min read
  • move_to_element method - Action Chains in Selenium Python
    Selenium’s Python Module is built to perform automated testing with Python. ActionChains are a way to automate low-level interactions such as mouse movements, mouse button actions, keypress, and context menu interactions. This is useful for doing more complex actions like hover over and drag and dro
    2 min read
  • pause method - Action Chains in Selenium Python
    Selenium’s Python Module is built to perform automated testing with Python. ActionChains are a way to automate low-level interactions such as mouse movements, mouse button actions, keypress, and context menu interactions. This is useful for doing more complex actions like hover over and drag and dro
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences