To release the cursor after clicking and holding the file, we can use the release() method to detach the files or folders from the cursor. In the below example code, I had written to login at drive.google.com.
After logged in, there will be one pdf file and one folder named(Move here). Imagine this is the scenario, that i want move the files to the folder. Below code will execute the same.
First we need to assign the webelement of the pdf file into the variable.
Second thing, we need to assign the webelement of the folder in to the variable.
After that, it will just click and hold the webelement of the file and release it to the folder which means the pdf file will be moved to the Move here folder.
Just copy and paste the below code it to your IDE(Ex: Eclipse), and run it for demo.
Java API Syntax : public Actions release(WebElement onElement)
I have create the demo video : Click here for the link : Selenium with JAVA - How to move the files or folders from one location to another location?
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 ReleaseOnWebElement { public static void main(String... args) throws InterruptedException { //Invoke FirefoxBrowser WebDriver dr = new FirefoxDriver(); //Login drive.google.com with user id and password dr.get("https://www.drive.google.com"); dr.findElement(By.id("Email")).sendKeys("onlytest628"); 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("steverock@123"); Thread.sleep(1000); dr.findElement(By.id("signIn")).click(); Thread.sleep(5000); //Assign the webelement into variables WebElement xyAxisPoint = dr.findElement(By.className("k-v-ta-za-Ln-vd")); WebElement moveHere = dr.findElement(By.className("k-v-M")); //click and hold the file(webelement) then move to the folder(on another webelement) Actions builder = new Actions(dr); builder.clickAndHold(xyAxisPoint) .release(moveHere) .perform(); } }