What is the Actions Class in Selenium?

What is the Actions Class in Selenium?

Generally, during online shopping, we have seen many keyboard and mouse events such as, when you click the right side of the mouse on any of the items on the website, an action is performed. ![This is image...

Generally, during online shopping, we have seen many keyboard and mouse events such as, when you click the right side of the mouse on any of the items on the website, an action is performed. This is image title

Similarly, when we use a browser with a Grammarly extension, then you might have observed that if you click twice on any word, then a message is displayed showing you the meaning of that word. These actions of the mouse or a keyboard, are done with the help of Action class in Selenium online training. What is an Action Class in Selenium? It is an integrated ability, for controlling different kinds of mouse and keyboard events. We have to use org.openqa.selinium.interactions Action class, to perform action events. Instead of using Mouse or keyboard directly, we can use the Selenium actions class. There are two classes in Selenium. They are Actions Class and Action Class. Action Class in Selenium: Action Class in Selenium is an interface, that is used to indicate one-user communication to do a sequence of action items, designed by Actions Class.

Actions Class: Actions Class designs complex actions with Selenium Web Driver. We can find the availability of the web-based elements, on the web application using Web Driver.

Syntax of Action Class:

//Configure the Action Actions action = new Actions ( driver); //To click on the element Action.moveToElement ( element).click( ). Perform( );

There are two main categories in the methods of Actions Class in Selenium. They are. Keyboard Interface Mouse Interface Various methods to perform Keyboard Events: KeyUp(modifier key) – used to modify key press release action. KeyDown(modifier key) – Continuous interactions can accept when key pressed. Accepts keys like keys.CONTROL, Keys.ALT, Keys.SHIFT etc. sendKeys(keys to send) – used to send continuous key presses, on to a web component. It takes two parameters. Various methods to perform Mouse Events: Release( ) – frees the flat left mouse button, at the present mouse place. moveToElement(toElement): Moves the mouse to the center of the component. It takes one parameter. moveByOffset(x-offset, y-offset) – Moves the mouse from its present position(or 0,0) by the specific offset. dragAndDropBy(source, xOffset, yOffset) – click and hold at the source element place, and moves by a specific offset. drag and drop( source, target) – click and hold at the source element location, and moves to the target element location. The source takes the component location, as the parameter. Target takes the item to move and free the mouse at the target component, as a parameter. click and hold( ) – Clicks without freeing in the center of the give component. context-click( ) – a context-click is done at the center of the given component. DoubleClick( ) – clicks twice at the present mouse place, click( ) – presses at the present mouse place. Let us see how Actions Class works in Selenium with an example: Example 1: Consider a situation, where we need to enter the Capital letters in the text box. First, create the Actions Class using the syntax. After creating the Actions Class, move the move over the Actions, and import the interactions package. Then find the component that you want to move, with the help of the web driver locators, like Xpath and use the moveToElement method to move to element. First ‘click’ the text box, then you can ‘type’ with Capital letters. To perform Click action, use ‘.click( )’ For sending capital text into text box, use ‘.keyDown(Key.SHIFT). For typing into text box, use ‘.sendKeys()’ Create command method ‘.build()’ Perform command method using ‘.perform()’. Example 2: Selecting a Text with the help of Selenium Webdriver Use ‘.doubleClick’ method for this example. First ‘click’ in the text box then ‘type’ with Upper Case letter and highlight or select complete text. Use ‘.click( )’ for clicking. Use ‘.keyDown(key.SHIFT)’ for sending upper case letters into the text box. Use ‘.sendkeys( )’, for typing into the text box. Use ‘.build( )’, a build command method. Use ‘.perform( )’, a perform command method. Use ‘.doubleClick’, for highlighting or selecting the complete text. These are the two examples showing how to use Actions class in Selenium webdriver. In this article, I have shared about Action Class in Selenium. Follow my articles to get more updates on Selenium.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Selenium WebDriver With Python 3.x - Novice To Ninja

Selenium WebDriver With Python 3.x - Novice To Ninja

Selenium Tutorial | Selenium Training | Selenium Course | Intellipaat

In this selenium tutorial you will learn end to end about selenium course. So in this selenium training video we have covered the concepts right from beginni...

Selenium Tutorial For Beginners - Selenium Webdriver Tutorial

Selenium is an automated testing tool that tests web applications across various platforms and browsers. In this Selenium Tutorial For Beginners - Selenium Webdriver Tutorial we will be learning about Selenium, its advent, compononents, advantages and limitations and lastly, its job roles and salaries. Selenium is a powerful tool and comprises of a suite of components viz. Selenium IDE, RC, WebDriver and Grid.