Thursday, April 17, 2014

DragAndDrop Example

 1. How to Move an Image from one image to another Image

package Login;
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 DragAndDrop {

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


        WebDriver driver = new FirefoxDriver();
        driver.get("http://devheart.org/examples/jquery-customizable-layout-using-drag-and-drop/2-saving-and-loading-items/index.html");
        driver.manage().window().maximize();
       
        Actions act= new Actions(driver);
        WebElement src= driver.findElement(By.xpath("//*[@id='B']"));
        WebElement Des= driver.findElement(By.xpath("//*[@id='E']"));
        Thread.sleep(2000);
        act.clickAndHold(src).build().perform();
        act.moveToElement(Des).build().perform();
        act.release(Des).build().perform();

    }

}


2. How to Drag an image from one place to another place.













package Login;
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.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Actions;

public class Drag1 {

    public static void main(String[] args) {
        FirefoxProfile prof = new FirefoxProfile();
        prof.setEnableNativeEvents(true);
        WebDriver driver = new FirefoxDriver(prof);

        driver.get("http://jqueryui.com/draggable/");
        driver.manage().window().maximize();

        // WebElement frame1 = driver.findElement(By.xpath("//*[@id='content']/iframe"));
        // System.out.println(frame1.getLocation());

        driver.switchTo().frame(0);
        Actions act = new Actions(driver);

        WebElement src = driver.findElement(By.xpath("//div[@id='draggable']"));
        System.out.println(src.getText());

        act.dragAndDropBy(src, 474, 360).build().perform();
    }

}

TestNG - Can i use the 2 different data providers to same @test methods in TestNG?

public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...