In this session you will learn how to handle Mouse event in Selenium Automation using Actions Class and what is the significance of Mouse events in automation
Covered below concepts
-----------------------------------------
MovetoElement
ContextClick
RightClick
Drag and Drop
Click and Hold
MovebyOffset
You can download this example program by scrolling to the bottom on the description and also you can import the complete example programs from below GitHub Repository
https://github.com/knowledgeshare-tec...
*******************************************************************
You can see step by step selenium sessions from below playlist
*******************************************************************
• How to handle WebTables using Seleniu...
For regular updates you can join this Group
***********************************************
/ 4754296501308288
****************************************************
Overview on Mouse Events
****************************************************
What are Mouse Events
Mouse hover to particular Webelement / Clicking / Double Click / Right Click etc.,
Different ways to automate Mouse Events
Using Actions class
What is the use of Mouse Actions
To hover on the WebElement to display dropdown Menu
Some Applications demand a right click on a webelement
to perform some Action
Getting colours on Mouse hovers
What Mouse Action you can perform using Actions Class
Single Click, Double Click, Right Click/Context Click, click and hold
Drag and drop , drag and drop by coordinates,
Move mouse to coordinates ( x, y)
Move to any Element
************************************************
Move to element and context click
----------------------------------------------------------------
package MouseEvents;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class MouseEvents_MovetoElement_ContextClick {
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", ".\\drivers\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.navigate().to("https://knowledgesharetechnologies.00...");
driver.manage().window().maximize();
Actions action=new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//*[@id=\"ResponsiveMenu1\"]/li[6]/a"))).build().perform();
Thread.sleep(3000);
action.moveToElement(driver.findElement(By.xpath("//*[@id=\"ResponsiveMenu1\"]/li[6]/ul/li[1]/a"))).build().perform();
Thread.sleep(3000);
action.moveToElement(driver.findElement(By.xpath("//*[@id=\"ResponsiveMenu1\"]/li[6]/ul/li[1]/ul/li[2]/a"))).build().perform();
Thread.sleep(3000);
action.contextClick().build().perform();
}
}
*********************************************
Move by Offest
**********************************************
package MouseEvents;
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 MouseEvents_MovebyOffest
{
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", ".\\drivers\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.navigate().to("https://knowledgesharetechnologies.00...");
driver.manage().window().maximize();
Thread.sleep(3000);
WebElement source=driver.findElement(By.xpath("//*[@id=\"ResponsiveMenu1\"]/li[6]/a"));
int x=source.getLocation().getX();
int y=source.getLocation().getY();
System.out.println("X cord : " + x);
System.out.println("Y cord : " + y);
Actions action=new Actions(driver);
action.moveByOffset(x, y).build().perform();
Thread.sleep(3000);
}
}
***************************
Drag and Drop Example
*****************************
package MouseEvents;
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 MouseEvents_Drag_and_Drop {
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", ".\\drivers\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.navigate().to("https://crossbrowsertesting.github.io...");
driver.manage().window().maximize();
WebElement source=driver.findElement(By.xpath("//*[@id=\"draggable\"]"));
WebElement target=driver.findElement(By.xpath("//*[@id=\"droppable\"]"));
Actions action=new Actions(driver);
action.dragAndDrop(source, target).build().perform();
}
}
Смотрите видео Handling Mouse events in Selenium Automation II WebDriver Selenium Automation онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Knowledge Share 11 Декабрь 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 34 раз и оно понравилось 1 людям.