Monday, 26 May 2014

Drag and drop a file or element from Source to Target place using selenium.

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class Vanmeter {



public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
driver.get("url"); // enter ur url here
driver.findElement(By.xpath("")).click(); //Enter the xpath locator in brace and click on the element
Actions act = new Actions(driver);
WebElement srcElement = driver.findElement(By.id(""));// enter the source element xpath or id
Thread.sleep(3000);
WebElement targetElement = driver.findElement(By.id(""));//enter the target xpath or id.
Thread.sleep(3000);
act.dragAndDrop(srcElement, targetElement);
Thread.sleep(3000);
act.build().perform();
Thread.sleep(3000);

}

}

No comments:

Post a Comment