Perform double click and right click

Double click action in Selenium web driver can be done using Actions class.

Right click operation is mostly used when performing right click on an element opens a new menu. Right click operation in Selenium web driver can be done using the pre-defined command Context Click

Actions action = new Actions(driver);
WebElement link = driver.findElement(By.ID ("Element ID"));
action.contextClick(link).perform();

Double click operation is used when the state of web element changes after double click operation. Double Click operation in Selenium web driver can be done using the pre defined command Double Click as mentioned below

Actions action = new Actions(driver);
WebElement link = driver.findElement(By.ID ("Element ID"));
action. doubleClick (link).perform();

Please refer below Program to understand how to perform double click and right click:

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 DoubleAndRightClick {

 public static void main(String[] args) throws InterruptedException {

 
  WebDriver driver;

  System.setProperty("webdriver.chrome.driver","C:\\Users\\Hitendra\\Downloads\\chromedriver_win32\\chromedriver.exe");

  driver = new ChromeDriver();

  driver.manage().window().maximize();

  driver.get("https://www.automationtestinginsider.com/2019/08/textarea-textarea-element-defines-multi.html");

  Thread.sleep(1000);  

  WebElement doubleClickBtn= driver.findElement(By.id("doubleClickBtn"));

  WebElement rightClickBtn= driver.findElement(By.id("rightClickBtn"));  

  Actions act= new Actions(driver);  

  act.doubleClick(doubleClickBtn).perform();

  System.out.println("Double clicked");

  Thread.sleep(2000);

  driver.switchTo().alert().accept();

  Thread.sleep(2000);

  act.contextClick(rightClickBtn).perform();

  Thread.sleep(2000);

  driver.close();

 }

}

Please refer below youtube video to understand How to Perform double click and right click:



1 comment: