How to clickAndHold at current location?

clickAndHold method is used to click the element and hold the element to move from one location to another location according to X and Y axis.  This method will help user to drag and drop files or folders from one place to another place.

User can use this method to move the cursor points as well.

Java API Syntax : public Actions clickAndHold(WebElement element)

Below code is an example to clickAndHold the files.

Note : Replace your login credentials for Sign in.

Code:
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class ClickAndHold
{
public static void main(String... args) throws InterruptedException {
WebDriver dr = new FirefoxDriver();
dr.get("https:\\www.drive.google.com");   
dr.findElement(By.id("Email")).sendKeys("xxxxxx");
dr.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
dr.findElement(By.id("next")).click();
dr.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
dr.findElement(By.id("Passwd")).sendKeys("xxxx@xxx");
Thread.sleep(1000);
dr.findElement(By.id("signIn")).click(); 
Thread.sleep(5000);

//To get the location of X and Y axis
System.out.println(dr.findElement(By.className("k-v-ta-za-Ln-vd")).getLocation());

//click and hold the webelement 
Actions builder = new Actions(dr);
builder.moveByOffset(225, 139)
.clickAndHold()
.moveByOffset(245, 175)
.perform();
}
}
Socialize It and Share the post with your friends
SOCIALIZE IT →
FOLLOW US →
SHARE IT →