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

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

Introduction

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

Prototype

public Actions clickAndHold(WebElement target) 

Source Link

Document

Clicks (without releasing) in the middle of the given element.

Usage

From source file:com.atanas.kanchev.testframework.selenium.handlers.Interact.java

License:Apache License

/**
 * {@inheritDoc}//from  w w  w.jav  a  2 s  .c  om
 */
@Override
public Interact clickAndHold(int duration) {
    if (((SeleniumContext) context().getCurrentContext()).getCurrentElement() != null) {
        logger.debug("Click and Hold Element");
        Actions actions = new Actions(((SeleniumContext<WebDriver>) context().getCurrentContext()).getDriver());
        actions.clickAndHold(((SeleniumContext) context().getCurrentContext()).getCurrentElement()).perform();
        sleep(duration);
        actions.release(((SeleniumContext) context().getCurrentContext()).getCurrentElement()).perform();

    } else {
        logger.error("clickAndHold() : Element is Null");

    }
    return this;
}

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

License:Open Source License

@Override
public void dragAndDropAnElement(WebElement findLocator, WebElement destination) {
    new Actions(webDriver);
    Actions dragdrop = new Actions(webDriver);
    try {/*  w  w  w .ja v a 2  s. com*/
        dragdrop.clickAndHold(findLocator).moveToElement(destination).release(destination).build().perform();
    } catch (StaleElementReferenceException se) {
        log.error("Stale element:", se);
    } catch (NoSuchElementException ne) {
        log.error("no such element: source: {}, destination:{}", findLocator, destination);
        log.error("message: {}", ne);
    } catch (Exception e) {
        log.error("unexpected error attempting to drag and drop", e);
    }
}

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
 *
 * @param locator// w w  w  . j a v  a 2  s  .c  om
 */
@Override
public void dragAndDropAnElement(String sourceElement, String destinationElement, int timeoutInSeconds) {
    Actions builder = new Actions(getWebDriver());
    WebElement sElement = findElement(sourceElement, timeoutInSeconds);
    WebElement dElement = findElement(destinationElement, timeoutInSeconds);
    builder.clickAndHold(sElement).moveToElement(dElement).release(dElement).build().perform();
}

From source file:com.ecofactor.qa.automation.platform.action.impl.DesktopUIAction.java

License:Open Source License

/**
 * Drag element.//from  w  w w . j a  va2 s .c  om
 * @param srcElement the src element
 * @param xOffset the x offset
 * @param yOffset the y offset
 * @see com.ecofactor.qa.automation.platform.action.UIAction#dragElement(org.openqa.selenium.WebElement,
 *      org.openqa.selenium.WebElement)
 */
@Override
public void dragElement(final WebElement srcElement, final Integer xOffset, final Integer yOffset) {

    setLogString("Drag element..", true, CustomLogLevel.HIGH);
    final Actions builder = new Actions(driverOps.getDeviceDriver());
    oneSec();
    builder.clickAndHold(srcElement).build().perform();
    oneSec();
    builder.moveByOffset(xOffset, yOffset).build().perform();

}

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

License:Open Source License

public void clickAndHold(int numRetries) {
    for (int i = 0; i < 5; i++) {
        try {/*from  www  . j  a v a2 s . c om*/
            WebElement webElem = findElement(numRetries);
            Actions actions = new Actions(browser.getSeleniumWebDriver());
            actions.clickAndHold(webElem).build().perform();
            break;
        } catch (MoveTargetOutOfBoundsException | ElementNotVisibleException ex) {
            browser.waitForSeconds(2);
        }
    }
}

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

License:Apache License

/**
 * click and hold element./*www .  jav  a 2 s . co m*/
 * @param xpath
 * the element's xpath
 */
public void clickAndHold(String xpath) {
    waitElement(xpath, timeout);

    Actions action = new Actions(browser);
    WebElement we = browser.findElement(By.xpath(xpath));

    action.clickAndHold(we).perform();
}

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

License:Open Source License

@Override
public void mouseDown(String locator) {
    WebElement webElement = getWebElement(locator);

    scrollWebElementIntoView(webElement);

    WrapsDriver wrapsDriver = (WrapsDriver) webElement;

    WebDriver webDriver = wrapsDriver.getWrappedDriver();

    Actions actions = new Actions(webDriver);

    actions.moveToElement(webElement);/*from  w w  w  . j  av  a 2 s  .  co m*/

    actions.clickAndHold(webElement);

    Action action = actions.build();

    action.perform();
}

From source file:com.mycompany.fullslidertest.FullsliderTest.java

public void drawEllipseAndChangeOpacity() {
    createPresentation("Draw Ellipse and change opacity");
    waitForAction();// w w  w  . j  a v a  2  s  .  c  o m

    driver.findElement(By.id("drawEllipse")).click();

    WebElement canvas = driver.findElement(By.id("canvas"));

    Actions builder = new Actions(driver);
    Action drawOnCanvas = builder.clickAndHold(canvas).moveByOffset(60, 60).release().build();
    drawOnCanvas.perform();

    driver.findElement(By.id("editEnd")).click();

    WebElement code = driver.findElement(By.xpath("//div[@id='workspace']/div[2]/div/section/div[3]"));
    actions.doubleClick(code).build().perform();
    waitForAction();

    driver.findElement(By.id("edit-fill-opacity")).click();
    driver.findElement(By.xpath("//select[@id='edit-fill-opacity']/option[7]")).click();
    driver.findElement(By.id("workspace")).click();

    waitForAction();
    driver.quit();
}

From source file:com.osbitools.ws.shared.prj.xui.GenericPrjMgrGuiWebTest.java

License:LGPL

public void dragDrop(WebElement from, WebElement to) {
    Actions builder = new Actions(driver);

    Action dragAndDrop = builder.clickAndHold(from).moveToElement(to).release(to).build();

    dragAndDrop.perform();//from w w  w. j  a  va2s .  com
}

From source file:com.vmware.gemfire.tools.pulse.tests.PulseAbstractTest.java

License:Apache License

public void testTreeMapPopUpData(String S1, String gridIcon) {
    for (int i = 1; i <= 3; i++) {
        searchByLinkAndClick(CLUSTER_VIEW_LABEL);
        if (gridIcon.equals(SERVER_GROUP_GRID_ID)) {
            WebElement ServerGroupRadio = driver.findElement(By.xpath("//label[@for='radio-servergroups']"));
            ServerGroupRadio.click();/* ww  w  . jav  a2 s. c  o m*/
        }
        if (gridIcon.equals(REDUNDANCY_GRID_ID)) {
            WebElement ServerGroupRadio = driver.findElement(By.xpath("//label[@for='radio-redundancyzones']"));
            ServerGroupRadio.click();
        }
        searchByIdAndClick(gridIcon);
        WebElement TreeMapMember = driver.findElement(By.xpath("//div[@id='" + S1 + "M" + (i) + "']/div"));
        Actions builder = new Actions(driver);
        builder.clickAndHold(TreeMapMember).perform();
        int j = 1;
        String CPUUsageM1temp = driver
                .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div/div[2]/div")).getText();
        String CPUUsageM1 = CPUUsageM1temp.replaceAll("[\\%]", "");
        String cpuUsageM1 = JMXProperties.getInstance().getProperty("member.M" + (i) + ".cpuUsage");
        assertEquals(cpuUsageM1, CPUUsageM1);

        String MemoryUsageM1temp = driver
                .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[" + (j + 1) + "]/div[2]/div"))
                .getText();
        String MemoryUsageM1 = MemoryUsageM1temp.replaceAll("MB", "");
        String memoryUsageM1 = JMXProperties.getInstance().getProperty("member.M" + (i) + ".UsedMemory");
        assertEquals(memoryUsageM1, MemoryUsageM1);

        String LoadAvgM1 = driver
                .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[" + (j + 2) + "]/div[2]/div"))
                .getText();
        String loadAvgM1 = JMXProperties.getInstance().getProperty("member.M" + (i) + ".loadAverage");
        assertEquals(df2.format(Double.valueOf(loadAvgM1)), LoadAvgM1);

        String ThreadsM1 = driver
                .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[" + (j + 3) + "]/div[2]/div"))
                .getText();
        String threadsM1 = JMXProperties.getInstance().getProperty("member.M" + (i) + ".numThreads");
        assertEquals(threadsM1, ThreadsM1);

        String SocketsM1 = driver
                .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[" + (j + 4) + "]/div[2]/div"))
                .getText();
        String socketsM1 = JMXProperties.getInstance()
                .getProperty("member.M" + (i) + ".totalFileDescriptorOpen");
        assertEquals(socketsM1, SocketsM1);
        builder.moveToElement(TreeMapMember).release().perform();
    }
}