Brief description of mouse action in selenium

Posted By : Jatin Singh | 31-Aug-2020

 

mouse action in selenium

 

 

In this tutorial, we are going to provide an introduction to mouse hover action in Selenium. Subsequently, you will learn how to perform the mouse hover action in Selenium WebDriver for web application testing.

 

Action class: Action class is an advance class in selenium, use to perform mouse related action, such as:

1- Mouse hover action,

2-Double click action

3-Right click action

4-Drag and drop action

 

NOTE- To use the methods present in the actions class we have to create an object of the action class.construtor of action class is parameterised , we have to pass web driver reference to the constructor of action class.

 

Mouse hover action : Mouse hover is an action in which user places a mouse over a paricular area like hyperlink,it displays some pop up window or description boxes.

 

Example program: WAP to perform mouse hover action.

WebDriver driver = new chrome driver();
driver.get ("Enter the URL");
Web element men Menu = driver.findelement(By.xpath(" xpath of the web element "));
Actions act =new Actions(driver);
act.movetoelement(menMenu).perform();
}
}

 

Double Click action: It is used to perform double click operation in selenium webdriver.

 

Example program: WAP to perform double click action.

WebDriver driver = new chrome driver();
driver.get ("Enter the URL");
Web element menMenu = driver.findelement(By.xpath(" xpath of the web element "));
Actions act =new Actions(driver);
act.doubleclick(btn1).perform();
}
}

 

Right Click action:It is used to perform right click operation in selenium webdriver.

 

Example program: WAP to perform right click action.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class prac5 {
static {
System.setProperty("webdriver.chrome.driver","./software/chromedriver.exe");
}
public static void main(String[] args) throws InterruptedException {
WebDriver driver=new ChromeDriver();
driver.get("Enter the URL");
Thread.sleep(4000);

driver.findElement(By.linkText("Slider")).click();
WebElement frameOne = driver.findElement(By.xpath("xpath of the web element"));
driver.switchTo().frame(frameOne);

WebElement slider = driver.findElement(By.id("slider"));
Actions act =new Actions(driver);
act.contextClick(slider).perform();
}

 

Drag and drop: Some of the application have functionality to drag web elements and drop them on defined area . we can automate drag and drop by using action class.

 

Example program: wap to perform drag and drop operation
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

public class prac3 {
static {
System.setProperty("webdriver.chrome.driver","./software/chromedriver.exe");
}
public static void main(String[] args) throws InterruptedException {
WebDriver driver=new ChromeDriver();
driver.get("Enter the URL");
Thread.sleep(4000);

driver.findElement(By.linkText("Droppable")).click();
WebElement frameOne = driver.findElement(By.xpath("//iframe[@class='demo-frame']"));
driver.switchTo().frame(frameOne);

WebElement srcElement = driver.findElement(By.id("draggable"));
WebElement targetElement = driver.findElement(By.id("droppable"));
Thread.sleep(4000);

Actions act = new Actions(driver);
act.dragAndDrop(srcElement, targetElement).perform();



}
}

We are a seasoned ERP software development company that specializes in building data-driven ERP applications to address varied business requirements. Our end-to-end ERP application development services include quality assurance and software testing to render seamless app performance with minimal complexities. Our team of QA engineers is skilled at performing web application testing using agile methodologies and advanced automation testing tools like Selenium, JMeter, and Katalon Studio.

 


Please remove URL from text

Comment is required

Sending message..
Connect with us