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

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

Introduction

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

Prototype

public Actions(WebDriver driver) 

Source Link

Usage

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

License:Open Source License

@Override
public void doubleClick(int numRetries) {
    try {/*from ww w.j ava2s.  c o m*/
        for (int i = 0; i < 5; i++) {
            try {
                WebElement webElem = findElement(numRetries);
                webElem.click();

                Actions webActions = new Actions(browser.getSeleniumWebDriver());
                webActions.doubleClick().build().perform();
                break;
            } catch (MoveTargetOutOfBoundsException | ElementNotVisibleException ex) {
                browser.waitForSeconds(2);
            }
        }
    } catch (Throwable th) {
        Assert.fail("Failed to perform mouse double click on element '" + domObject.getDisplayName() + "'.",
                th);
    }
}

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  w ww  .ja v a2s  .  co  m*/
            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.induscorp.prime.testing.ui.core.objects.DOMObjectValidator.java

License:Open Source License

public void release(int numRetries) {
    for (int i = 0; i < 5; i++) {
        try {/*from w  ww.  ja va2  s.  c om*/
            WebElement webElem = findElement(numRetries);
            Actions actions = new Actions(browser.getSeleniumWebDriver());
            actions.release(webElem).build().perform();
            break;
        } catch (MoveTargetOutOfBoundsException | ElementNotVisibleException ex) {
            browser.waitForSeconds(2);
        }
    }
}

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

License:Open Source License

public void dragAndDrop(DOMObject target, int numRetries) {
    try {//from   w  w w. ja  va  2 s. com
        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.induscorp.prime.testing.ui.core.objects.DOMObjectValidator.java

License:Open Source License

public void performKeyDown(Keys keys, int numRetries) {
    for (int i = 0; i < 5; i++) {
        try {//from w  w w . j av a  2  s  . com
            WebElement webElem = findElement(numRetries);
            Actions actions = new Actions(browser.getSeleniumWebDriver());
            actions.keyDown(webElem, keys).build().perform();
            break;
        } catch (MoveTargetOutOfBoundsException | ElementNotVisibleException ex) {
            browser.waitForSeconds(2);
        }
    }
}

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

License:Open Source License

public void performKeyUp(Keys keys, int numRetries) {
    for (int i = 0; i < 5; i++) {
        try {// w  ww .  j  a v  a 2 s .c o  m
            WebElement webElem = findElement(numRetries);
            Actions actions = new Actions(browser.getSeleniumWebDriver());
            actions.keyUp(webElem, keys).build().perform();
            break;
        } catch (MoveTargetOutOfBoundsException | ElementNotVisibleException ex) {
            browser.waitForSeconds(2);
        }
    }
}

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

License:Open Source License

public void performKeyPressed(Keys keys, int numRetries) {
    for (int i = 0; i < 5; i++) {
        try {//from  w w  w.  j a va2 s  .co m
            WebElement webElem = findElement(numRetries);
            Actions actions = new Actions(browser.getSeleniumWebDriver());
            actions.keyDown(webElem, keys).keyUp(webElem, keys).build().perform();
            break;
        } catch (MoveTargetOutOfBoundsException | ElementNotVisibleException ex) {
            browser.waitForSeconds(2);
        }
    }
}

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

License:Open Source License

public void typeText(String text, NewTextLocation location, int numRetries) {
    String newtext;/*from w w w  .  j ava2  s. co m*/
    Actions actions;
    for (int i = 0; i < 5; i++) {
        try {
            WebElement webElem = findElement(numRetries);
            ClipboardUtil.clearContents();

            try {
                actions = new Actions(browser.getSeleniumWebDriver());
                actions.sendKeys(webElem, Keys.CONTROL + "ax").build().perform();
            } finally {
                actions = new Actions(browser.getSeleniumWebDriver());
                actions.keyUp(webElem, Keys.CONTROL).build().perform();
            }

            String existingText = ClipboardUtil.getContents();
            ClipboardUtil.clearContents();

            switch (location) {
            case start:
                newtext = text + existingText;
                actions = new Actions(browser.getSeleniumWebDriver());
                actions.sendKeys(webElem, newtext).build().perform();
                break;
            case end:
                newtext = existingText + text;
                actions = new Actions(browser.getSeleniumWebDriver());
                actions.sendKeys(webElem, newtext).build().perform();
                break;
            case replace:
                actions = new Actions(browser.getSeleniumWebDriver());
                actions.sendKeys(webElem, text).build().perform();
                break;
            }

            break;
        } catch (MoveTargetOutOfBoundsException | ElementNotVisibleException ex) {
            browser.waitForSeconds(2);
        }
    }
}

From source file:com.jaeksoft.searchlib.crawler.web.browser.BrowserDriver.java

License:Open Source License

/**
 * Click on the given WebElement using Actions
 * //from  ww  w.  ja v  a 2s.  c  om
 * @param element
 * @return
 */
public void click(WebElement element) {
    Actions builder = new Actions(driver);
    Action click = builder.moveToElement(element).click(element).build();
    click.perform();
}

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

License:Apache License

/**
 * Right click element./*w w w .  j a v a2 s .  c om*/
 * @param xpath
 * the element's xpath
 */
public void rightClick(String xpath) {
    waitElement(xpath, timeout);

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

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