Example usage for org.openqa.selenium.interactions Actions dragAndDrop

List of usage examples for org.openqa.selenium.interactions Actions dragAndDrop

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Actions dragAndDrop.

Prototype

public Actions dragAndDrop(WebElement source, WebElement target) 

Source Link

Document

A convenience method that performs click-and-hold at the location of the source element, moves to the location of the target element, then releases the mouse.

Usage

From source file:au.edu.qtac.admission.webtest.DragAndDropTest.java

@Test
public void shouldBeAbleToDragAndDrop() {
    driver.navigate().to("http://pfdemo-peterdemo101.rhcloud.com/pfdemo/dragdrop.xhtml");
    Actions builder = new Actions(driver);

    //        Action dragAndDrop = builder.clickAndHold(driver.findElement(By.id("j_idt11_header")))
    //                .moveByOffset(100, 300).release().build();

    Action dragAndDrop = builder.dragAndDrop(driver.findElement(By.className("ui-draggable")),
            driver.findElement(By.className("ui-droppable"))).build();

    dragAndDrop.perform();//from   w  ww .  j a v a 2  s .  com

    try {
        Thread.sleep(5000);
    } catch (InterruptedException ex) {
        Logger.getLogger(DragAndDropTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:browsermator.com.DragAndDropAction.java

@Override
public void RunAction(WebDriver driver) {

    try {/*from  ww w.j  a va 2s.c o  m*/

        WebElement dragElement = driver.findElement(By.xpath(this.Variable1));
        WebElement dropElement = driver.findElement(By.xpath(this.Variable2));

        Actions actions = new Actions(driver);
        actions.dragAndDrop(dragElement, dropElement).perform();

        this.Pass = true;
    } catch (Exception e) {
        this.Pass = false;
        System.out.println("Exception: " + e);

    }
}

From source file:com.cengage.mindtap.keywords.DashBoardPageActions.java

public void verifySkimmerFunctionality() {

    WebElement DragPos = element("DragPos");
    WebElement DropPos = element("DropPos");
    WebElement DropWeek2 = element("DragPosWeek2");
    Actions act = new Actions(driver);
    act.dragAndDrop(DragPos, DropPos).build().perform();
    Assert.assertTrue(element("verifyWeek").isDisplayed(), "Week View is not enable or set as default");
    waitTOSync();//  w w w  .  j av a 2  s  .co  m
    waitTOSync();
    waitTOSync();
    act.dragAndDrop(DropPos, DropWeek2).build().perform();

}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * This method uses the webDriver object to drag and drop the elements from source to destination using javascript
 *
 * @param locator/*ww  w . j a  va 2 s . c  o m*/
 */
@Override
public void dragAndDropAnElementUsingJavascript(String sourceElement, String destinationElement,
        int timeoutInSeconds) {
    Actions builder = new Actions(getWebDriver());
    WebElement src = findElement(sourceElement, timeoutInSeconds);
    WebElement des = findElement(destinationElement, timeoutInSeconds);
    String xto = Integer.toString(src.getLocation().x);
    String yto = Integer.toString(des.getLocation().y);
    JavascriptExecutor executor = (JavascriptExecutor) webDriver;
    String event = "function simulate(f,c,d,e){var b,a=null;for(b in eventMatchers)if(eventMatchers[b].test(c)){a=b;break}if(!a)return!1;document.createEvent?(b=document.createEvent(a),a==\"HTMLEvents\"?b.initEvent(c,!0,!0):b.initMouseEvent(c,!0,!0,document.defaultView,0,d,e,d,e,!1,!1,!1,!1,0,null),f.dispatchEvent(b)):(a=document.createEventObject(),a.detail=0,a.screenX=d,a.screenY=e,a.clientX=d,a.clientY=e,a.ctrlKey=!1,a.altKey=!1,a.shiftKey=!1,a.metaKey=!1,a.button=1,f.fireEvent(\"on\"+c,a));return!0} var eventMatchers={HTMLEvents:/^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,MouseEvents:/^(?:click|dblclick|mouse(?:down|up|over|move|out))$/}; "
            + "simulate(arguments[0],\"mousedown\",0,0); simulate(arguments[0],\"mousemove\",arguments[1],arguments[2]); simulate(arguments[0],\"mouseup\",arguments[1],arguments[2]); ";
    try {
        src.click();
        des.click();
        builder.dragAndDrop(src, des);
    } catch (Exception e) {
        executor.executeScript(event, src, xto, yto);
    }
}

From source file:com.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Drag and drop./*from w  w w.jav  a  2 s  . c  o m*/
 * 
 * @param driver the driver
 * @param fromElement the from element
 * @param toElement the to element
 * @param xOffset the x offset
 * @param yOffset the y offset
 */
public static void dragAndDrop(final WebDriver driver, final WebElement fromElement, final WebElement toElement,
        final int xOffset, final int yOffset) {

    final Actions builder = new Actions(driver);
    builder.dragAndDrop(fromElement, toElement).build().perform();

}

From source file:com.example.selenium.action.DragDrop.java

@Test
public void testDragDrop() throws InterruptedException {

    WebElement source = driver.findElement(By.id("d1"));
    WebElement target = driver.findElement(By.id("target"));

    Thread.sleep(2000);//from   ww  w .j a  v  a2 s .c o  m
    Actions builder = new Actions(driver);
    builder.dragAndDrop(source, target).perform();
    Thread.sleep(1000);
    WebElement element = driver.findElement(By.xpath("//div[2]/div"));
    Assert.assertNotNull(element);

}

From source file:com.induscorp.prime.testing.ui.core.objects.DOMObjectValidator.java

License:Open Source License

public void dragAndDrop(DOMObject target, int numRetries) {
    try {/* w  ww .j  av a  2 s. c o  m*/
        for (int i = 0; i < 5; i++) {
            try {
                WebElement sourceElem = findElement(numRetries);
                WebElement targetElem = target.getValidator(browser, region).findElement(numRetries);

                Actions webActions = new Actions(browser.getSeleniumWebDriver());
                webActions.dragAndDrop(sourceElem, targetElem).build().perform();
                break;
            } catch (MoveTargetOutOfBoundsException | ElementNotVisibleException ex) {
                browser.waitForSeconds(2);
            }
        }
    } catch (Throwable th) {
        Assert.fail("Failed to perform dragAndDrop from source '" + domObject.getDisplayName() + "' to target '"
                + target.getDisplayName() + "'.", th);
    }
}

From source file:com.jase.knife.BrowserEmulator.java

License:Apache License

/**
 * Drags an element a certain distance and then drops it.
 * @param el_xpath, the element's xpath/* ww  w  . j  ava 2  s  . c  o m*/
 * @param ta_xpath, the element's xpath
 */
public void dragAndDrop(String el_xpath, String ta_xpath) {
    waitElement(el_xpath, timeout);
    waitElement(ta_xpath, timeout);

    Actions action = new Actions(browser);
    WebElement el = browser.findElement(By.xpath(el_xpath));
    WebElement ta = browser.findElement(By.xpath(ta_xpath));

    action.dragAndDrop(el, ta).perform();
}

From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java

License:Open Source License

@Override
public void dragAndDropToObject(String locatorOfObjectToBeDragged, String locatorOfDragDestinationObject) {

    WebElement objectToBeDraggedWebElement = getWebElement(locatorOfObjectToBeDragged);

    WrapsDriver wrapsDriver = (WrapsDriver) objectToBeDraggedWebElement;

    WebDriver webDriver = wrapsDriver.getWrappedDriver();

    Actions actions = new Actions(webDriver);

    WebElement dragDestinationObjectWebElement = getWebElement(locatorOfDragDestinationObject);

    actions.dragAndDrop(objectToBeDraggedWebElement, dragDestinationObjectWebElement);

    Action action = actions.build();

    action.perform();//from   w  w w. jav a 2  s .  c om
}

From source file:com.nabla.project.fronter.selenium.tests.helper.SeleniumHelper.java

License:Open Source License

public static void testDragDrop(final String draggable, final String droppable, String expectedResult,
        final WebDriver driver, final StringBuffer verificationErrors) {

    final WebElement source = driver.findElement(By.id(draggable));
    final WebElement target = driver.findElement(By.id(droppable));

    final Actions builder = new Actions(driver);
    builder.dragAndDrop(source, target).perform();
    try {//from  ww  w .  j  a v a 2s .co  m
        if (null == expectedResult) {
            expectedResult = "Dropped!";
        }
        Assert.assertEquals(expectedResult, target.getText());
    } catch (final Error e) {
        verificationErrors.append(e.toString());
    }
}