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

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

Introduction

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

Prototype

public Action build() 

Source Link

Document

Generates a composite action containing all actions so far, ready to be performed (and resets the internal builder state, so subsequent calls to #build() will contain fresh sequences).

Usage

From source file:be.rubus.web.testing.AbstractWidget.java

License:Apache License

protected void click(WebElement element, Keys... keys) {
    Actions builder = new Actions(driver);

    for (Keys key : keys) {
        builder.keyDown(key);//from   w w w. java2  s.  c o m
    }
    builder.click(element);
    for (Keys key : keys) {
        builder.keyUp(key);
    }

    Action action = builder.build();

    action.perform();
}

From source file:cat.calidos.morfeu.webapp.ui.UIWidget.java

License:Apache License

@SuppressWarnings("unchecked")
public T pressKey(String k) {

    // we are sending the keys this way as it seems to work as it should, selenide or selenium has a lot of trouble here

    Actions actions = new Actions(driver);
    //actions.moveToElement(element.getWrappedElement());
    //actions.click();
    actions.sendKeys(Keys.chord((CharSequence) k));
    actions.build().perform();

    // this keeps failing randomly
    try {//from   w  w w . j av a  2  s .c o m
        Thread.sleep(50);
    } catch (InterruptedException e) {
    }

    return (T) this;

}

From source file:cat.calidos.morfeu.webapp.ui.UIWidget.java

License:Apache License

@SuppressWarnings("unchecked")
public T pressBackspace() {

    WebDriver driver = element.getWrappedDriver();
    Actions actions = new Actions(driver);
    actions.sendKeys(Keys.BACK_SPACE);/*from   w w  w .j  a v a2s .c  om*/
    actions.build().perform();

    return (T) this;

}

From source file:cc.kune.selenium.SeleniumUtils.java

License:GNU Affero Public License

/**
 * Move mouse to.//from w  w  w  .j  av  a  2 s. c  o m
 * 
 * @param webdriver
 *          the webdriver
 * @param element
 *          the element
 * @param xOffset
 *          the x offset
 * @param yOffset
 *          the y offset
 */
public static void moveMouseTo(final WebDriver webdriver, final WebElement element, final int xOffset,
        final int yOffset) {
    showCursor(webdriver, element, xOffset, yOffset);
    final Actions actions = new Actions(webdriver);
    actions.moveToElement(element, xOffset, yOffset);
    final Action action = actions.build();
    action.perform();
}

From source file:cc.kune.selenium.SeleniumUtils.java

License:GNU Affero Public License

/**
 * Move mouse to and click.//from ww w .jav  a2  s. co  m
 * 
 * @param webdriver
 *          the webdriver
 * @param element
 *          the element
 * @param xOffset
 *          the x offset
 * @param yOffset
 *          the y offset
 */
public static void moveMouseToAndClick(final WebDriver webdriver, final WebElement element, final int xOffset,
        final int yOffset) {
    // showCursor(webdriver, element, xOffset, yOffset);
    final Actions actions = new Actions(webdriver);
    actions.moveToElement(element, xOffset, yOffset);
    actions.click();
    final Action action = actions.build();
    action.perform();
}

From source file:com.ataco.erzeta.TC_RZ_1.java

/**
 * TC-RZ-3 (hlavn)//from  ww w  .j av  a2s.  c  o  m
 * Test na vytvoen nov rezervace.
 */
@Test
public void testAddNewReservation() {
    clickPlusButton();

    NativeSelectElement sourceSelect = $(NativeSelectElement.class).first();
    sourceSelect.selectByText(testedSourceName);

    Calendar c = Calendar.getInstance();
    c.setTime(new Date());
    c.add(Calendar.DATE, 2);
    int day = c.get(Calendar.DAY_OF_MONTH);

    TestBenchElement datepicker = (TestBenchElement) findElements(
            By.cssSelector(".v-touchkit-datepicker-datePickerDetailView")).get(1);
    datepicker.focus();
    datepicker.click();
    Actions actions = new Actions(getDriver());
    actions.sendKeys(Integer.toString(day));
    actions.build().perform();

    SliderElement slider1 = $(SliderElement.class).first();
    slider1.click();
    actions = new Actions(getDriver());
    for (int i = 1; i < quantity; i++) {
        actions.sendKeys(Keys.ARROW_RIGHT);
    }
    actions.build().perform();

    TextAreaElement descriptionTextArea = $(TextAreaElement.class).caption("Popis:").first();
    descriptionTextArea.setValue(testedDescription);

    ButtonElement saveButton = $(ButtonElement.class).caption("ULOIT").first();
    saveButton.click();

    sleep(500);
    testDataFromNewReservation();
}

From source file:com.ataco.erzeta.TC_RZ_3.java

/**
 * TC-RZ-3 (hlavn)/* w  ww.  ja  v a 2  s.  co m*/
 * Test na vytvoen novho zdroje
 */
@Test
public void testAddNewSource() {
    NativeButtonElement menuButton = $(NativeButtonElement.class).caption("").first();
    menuButton.click();
    sleep(500);

    NativeButtonElement sourcesButton = $(NativeButtonElement.class).caption("Zdroje").first();
    sourcesButton.click();
    sleep(500);

    clickPlusButton();
    sleep(500);

    TextFieldElement nameLabel = $(TextFieldElement.class).caption("Nzev").first();
    nameLabel.setValue(testedSourceName);

    Calendar c = Calendar.getInstance();
    c.setTime(new Date());

    TestBenchElement existSince = (TestBenchElement) findElements(By.cssSelector(".v-touchkit-datepicker"))
            .get(0);
    existSince.focus();
    existSince.click();
    String sequence = String.format(
            "%s" + Integer.toString(c.get(Calendar.DAY_OF_MONTH)) + "%s"
                    + Integer.toString(c.get(Calendar.MONTH)) + Integer.toString(c.get(Calendar.YEAR)),
            c.get(Calendar.DAY_OF_MONTH) < 10 ? "0" : "", c.get(Calendar.MONTH) < 10 ? "0" : "");
    Actions actions = new Actions(getDriver());
    actions.sendKeys(sequence);
    actions.build().perform();

    TestBenchElement existTill = (TestBenchElement) findElements(By.cssSelector(".v-touchkit-datepicker"))
            .get(1);
    existTill.focus();
    existTill.click();
    actions = new Actions(getDriver());
    c.add(Calendar.DATE, 2);
    sequence = String.format(
            "%s" + Integer.toString(c.get(Calendar.DAY_OF_MONTH)) + "%s"
                    + Integer.toString(c.get(Calendar.MONTH)) + Integer.toString(c.get(Calendar.YEAR)),
            c.get(Calendar.DAY_OF_MONTH) < 10 ? "0" : "", c.get(Calendar.MONTH) < 10 ? "0" : "");
    actions.sendKeys(sequence);
    actions.build().perform();

    TextFieldElement capacityTextField = $(TextFieldElement.class).caption("Kapacita").first();
    capacityTextField.setValue(Integer.toString(capacity));

    TestBenchElement publicAccessSwitch = (TestBenchElement) findElement(By.cssSelector(".v-touchkit-switch"));
    publicAccessSwitch.click();
    sleep(100);

    TextAreaElement descriptionTextArea = $(TextAreaElement.class).caption("Popis").first();
    descriptionTextArea.setValue(testedDescription);

    TestBenchElement authorizationsTab = (TestBenchElement) findElements(By.cssSelector(".v-tabsheet-tabitem"))
            .get(1);
    authorizationsTab.click();

    clickPlusButton();

    NativeSelectElement usernameSelect = $(NativeSelectElement.class).first();
    usernameSelect.selectByText("testovaciJmeno testovaciPrijmeni");

    NativeButtonElement saveButton = $(NativeButtonElement.class).caption("ULOIT").first();
    saveButton.click();
    sleep(500);

    testDataFromNewReservation();
}

From source file:com.consol.citrus.selenium.actions.DropDownSelectAction.java

License:Apache License

@Override
protected void execute(WebElement webElement, SeleniumBrowser browser, TestContext context) {
    super.execute(webElement, browser, context);

    Select dropdown = new Select(webElement);

    if (StringUtils.hasText(option)) {
        dropdown.selectByValue(context.replaceDynamicContentInString(option));
    }//  w ww  .j a  v  a 2 s  . c o m

    if (!CollectionUtils.isEmpty(options)) {
        if (BrowserType.IE.equals(browser.getEndpointConfiguration().getBrowserType())) {
            for (String option : options) {
                dropdown.selectByValue(context.replaceDynamicContentInString(option));
            }
        } else {
            List<WebElement> optionElements = dropdown.getOptions();
            Actions builder = new Actions(browser.getWebDriver());
            builder.keyDown(Keys.CONTROL);
            for (String optionValue : options) {
                for (WebElement option : optionElements) {
                    if (!option.isSelected()
                            && isSameValue(option, context.replaceDynamicContentInString(optionValue))) {
                        builder.moveToElement(option).click(option);
                    }
                }
            }
            builder.keyUp(Keys.CONTROL);
            Action multiple = builder.build();
            multiple.perform();
        }
    }
}

From source file:com.consol.citrus.selenium.client.WebClient.java

License:Apache License

/**
 * Select multiple items from a pull-down list.
 *
 * @param by/* ww w. j  a  v  a 2  s . c  o m*/
 * @param from Start at index.
 * @param to End at index.
 */
public void selectMultipleItems(By by, int from, int to) {
    Select dropdown = new Select(findElement(by));

    if (BrowserTypeEnum.INTERNET_EXPLORER.equals(browserType)) {
        for (int i = from; i < to; i++) {
            dropdown.selectByIndex(i);
        }
    } else {
        //Rest:
        List<WebElement> options = dropdown.getOptions();
        Actions builder = new Actions(webDriver);
        builder.keyDown(Keys.CONTROL);
        for (int i = from; i < to; i++) {
            WebElement item = options.get(i);
            if (!item.isSelected()) {
                builder.moveToElement(item).click(item);
            }
        }
        builder.keyUp(Keys.CONTROL);
        Action multiple = builder.build();
        multiple.perform();
    }
}

From source file:com.liferay.blade.sample.test.functional.utils.BladeSampleFunctionalActionUtil.java

License:Apache License

public static void customClick(WebDriver webDriver, WebElement webElement) {
    Actions action = new Actions(webDriver);

    Actions actionMoveTo = action.moveToElement(webElement);

    Action buildActionMoveTo = actionMoveTo.build();

    buildActionMoveTo.perform();//from ww w. j  a  v  a  2  s . c om

    WebDriverWait wait = new WebDriverWait(webDriver, 30);

    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(webElement));

    element.click();
}