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

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

Introduction

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

Prototype

public Actions keyUp(WebElement target, CharSequence key) 

Source Link

Document

Performs a modifier key release after focusing on an element.

Usage

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 {/*from  ww  w  . j a  v  a  2s . co 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 typeText(String text, NewTextLocation location, int numRetries) {
    String newtext;/*  w  ww  . j a v  a  2  s  . com*/
    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.liferay.cucumber.selenium.BaseWebDriverImpl.java

License:Open Source License

@Override
public void keyPress(String locator, String keySequence) {
    WebElement webElement = getWebElement(locator);

    if (keySequence.startsWith("\\")) {
        String keycode = keySequence.substring(1);

        if (isValidKeycode(keycode)) {
            Keys keys = Keys.valueOf(keycode);

            WrapsDriver wrapsDriver = (WrapsDriver) webElement;

            WebDriver webDriver = wrapsDriver.getWrappedDriver();

            Actions actions = new Actions(webDriver);

            if (keycode.equals("ALT") || keycode.equals("COMMAND") || keycode.equals("CONTROL")
                    || keycode.equals("SHIFT")) {

                actions.keyDown(webElement, keys);
                actions.keyUp(webElement, keys);

                Action action = actions.build();

                action.perform();//from   w w  w .j a  va2  s  . com
            } else {
                webElement.sendKeys(keys);
            }
        }
    } else {
        webElement.sendKeys(keySequence);
    }
}

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

License:Open Source License

@Override
public void keyUp(String locator, String keySequence) {
    WebElement webElement = getWebElement(locator);

    WrapsDriver wrapsDriver = (WrapsDriver) webElement;

    WebDriver webDriver = wrapsDriver.getWrappedDriver();

    Actions actions = new Actions(webDriver);

    String keycode = keySequence.substring(1);

    Keys keys = Keys.valueOf(keycode);/*from  ww w  .ja v a2  s.co m*/

    actions.keyUp(webElement, keys);

    Action action = actions.build();

    action.perform();
}

From source file:org.finra.jtaf.ewd.widget.element.InteractiveElement.java

License:Apache License

@Override
public void keyUp(Keys theKey) throws WidgetException {
    try {/*w w  w  . ja va  2s .  com*/
        Actions builder = new Actions(getGUIDriver().getWrappedDriver());
        synchronized (InteractiveElement.class) {
            getGUIDriver().focus();
            for (org.openqa.selenium.Keys key : org.openqa.selenium.Keys.values()) {
                if (key.name().equals(theKey.name())) {
                    builder.keyUp(getWebElement(), key).build().perform();
                    break;
                }
            }
        }

    } catch (Exception e) {
        throw new WidgetException("Error while performing key up using " + theKey.name(), getLocator(), e);
    }
}