What Is The Use Of Action Class

Action Class

Whenever we want to perform any operation on the application, first we have to launch the browser and launch the application. The entire control of browser as well as the application is in the reference variable (eg: driver) of type WebDriver. So, by using reference variable, we can identify any element that is present in web application, where as to handle mouse events such as :

  1. Move the mouse hover certain elements
  2. Drag and drop
  • Right click and so on.

All these actions cannot be directly done using WebDriver reference variable. So in order to perform the mouse auctioning we need to make use of Action class.

Note : Any method that are used from actions class, it has to be followed by perfom method i.e; perform the previous action.

Actions refVariable = new Actions(arg)

refVariable.movetoElement.perform();

Ex :

WebElement ele = driver.findElement(ByXpath(…………));

Actions act =  new Actions(driver);

act.moveToElement(ele).perform();

  •  Right click

To perform right click operation, we have to make use of actins class. In actions class use the method by name contextClick [i.e; right click] and we call the options in the menu as context menu.

In order to use any options present in context menu we can’t inspect those options by it in browser based window. In order to click on any option in context menu, use the shortcut key.

Ex: open link in new Tab -> TWhat

Use these kind of shortcut keys in sendKeys().

Ex :

driver.get(http://www.makemytrip.com/);

WebElement ele = driver.findElement(By.Xpath(“//span[text()=’Hotels’]”);

Actions act =  new Actions(driver);

act.movetoElement(ele).perform();

act.contextClick().perform();

act.sendKey(“T”).perform();

Add Comment