How do you manage mouse and keyboard actions like context click, double click, mousemover, drag and drop?

Syntax for right click:-
Actions action = new Actions(driver);
By locator = By.xpath(“//span[@class=’context-menu-one btn btn-neutral’]”);
WebElement rightClickElement = driver.findElement(locator);

// contextClick is the method() of class Action
action.contextClick(rightClickElement).build().perform();

Syntax for mouseover ;-

Actions action = new Actions(driver);
System.out.println(“Mouse is over the – HELLO, SIGN IN – option”);

// moveToElement is the method() of class Action
action.moveToElement(element).build().perform();
//Thread.sleep(3000);
driver.findElement(By.xpath(“//span[contains(text(),’Create a List’)]”)).click();
System.out.println(“Clicked”);

Syntax for drag and drop ;-
Actions act = new Actions(driver);

// dragAndDrop is the method() of class Action
act.dragAndDrop(source, target).build().perform();
System.out.println(“drag N drop Done…”);
Thread.sleep(3000);
driver.close();

Leave a Reply