Example usage for org.openqa.selenium Keys ARROW_RIGHT

List of usage examples for org.openqa.selenium Keys ARROW_RIGHT

Introduction

In this page you can find the example usage for org.openqa.selenium Keys ARROW_RIGHT.

Prototype

Keys ARROW_RIGHT

To view the source code for org.openqa.selenium Keys ARROW_RIGHT.

Click Source Link

Usage

From source file:browsermator.com.RightArrowKeyAction.java

@Override
public void RunAction(WebDriver driver) {
    try {/*  w  w w.j  ava2  s .com*/
        WebElement element = driver.switchTo().activeElement();
        element.sendKeys(Keys.ARROW_RIGHT);
        this.Pass = true;
    } catch (Exception ex) {
        this.Pass = false;
    }

}

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

/**
 * TC-RZ-3 (hlavn)/*from www  .  j  a  v a  2  s  . c om*/
 * 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.cognifide.qa.bb.aem.dialog.classic.field.AemRichText.java

License:Apache License

/**
 * Selects text in the text area between indices provided as parameters.
 *
 * @param startPos the beginning position
 * @param endPos   the ending position//from   w w w.  j a va  2s  .c  om
 * @return This instance.
 */
public AemRichText selectText(int startPos, int endPos) {
    switchToTextArea();
    try {
        actions.sendKeys(Keys.chord(Keys.CONTROL, Keys.HOME)).perform();
        for (int i = 0; i < startPos; i++) {
            actions.sendKeys(Keys.ARROW_RIGHT).perform();
        }
        actions.keyDown(Keys.SHIFT);
        for (int i = 0; i < endPos - startPos; i++) {
            actions.sendKeys(Keys.ARROW_RIGHT);
        }
        actions.keyUp(Keys.SHIFT).perform();
        return this;
    } finally {
        frameSwitcher.switchBack();
    }
}

From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java

License:Apache License

/**
 * A test./*from w w  w  . j av  a  2 s.c  o  m*/
 */
@Test
public void shouldReportKeyCodeOfArrowKeys() {
    final WebDriver driver = getWebDriver("/javascriptPage.html");

    final WebElement result = driver.findElement(By.id("result"));
    final WebElement element = driver.findElement(By.id("keyReporter"));

    element.sendKeys(Keys.ARROW_DOWN);
    checkRecordedKeySequence(result, 40);

    element.sendKeys(Keys.ARROW_UP);
    checkRecordedKeySequence(result, 38);

    element.sendKeys(Keys.ARROW_LEFT);
    checkRecordedKeySequence(result, 37);

    element.sendKeys(Keys.ARROW_RIGHT);
    checkRecordedKeySequence(result, 39);

    // And leave no rubbish/printable keys in the "keyReporter"
    assertThat(element.getAttribute("value"), is(""));
}

From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java

License:Apache License

/**
 * A test./*from   w  w w  . ja  v a  2  s .c om*/
 */
@Test
public void shouldReportKeyCodeOfArrowKeysUpDownEvents() {
    final WebDriver driver = getWebDriver("/javascriptPage.html");

    final WebElement result = driver.findElement(By.id("result"));
    final WebElement element = driver.findElement(By.id("keyReporter"));

    element.sendKeys(Keys.ARROW_DOWN);
    assertThat(result.getText().trim(), containsString("down: 40"));
    assertThat(result.getText().trim(), containsString("up: 40"));

    element.sendKeys(Keys.ARROW_UP);
    assertThat(result.getText().trim(), containsString("down: 38"));
    assertThat(result.getText().trim(), containsString("up: 38"));

    element.sendKeys(Keys.ARROW_LEFT);
    assertThat(result.getText().trim(), containsString("down: 37"));
    assertThat(result.getText().trim(), containsString("up: 37"));

    element.sendKeys(Keys.ARROW_RIGHT);
    assertThat(result.getText().trim(), containsString("down: 39"));
    assertThat(result.getText().trim(), containsString("up: 39"));

    // And leave no rubbish/printable keys in the "keyReporter"
    assertThat(element.getAttribute("value"), is(""));
}

From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java

License:Open Source License

@Test
@RunAsClient//  ww  w  .  ja  v a  2s.com
@InSequence(1500)
public void dataEntry() throws Exception {

    String foo = "";

    logger.log(Level.INFO, "clicking into the firstNameField ...");
    firstNameField.click();
    logger.log(Level.INFO, "tabbing into the next field ...");
    firstNameField.sendKeys(Keys.TAB);

    logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value"));
    logger.log(Level.INFO,
            "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath));

    if (isThere(browser, firstNameFieldErrorXpath)) { // houston we have a problem
        logger.log(Level.INFO, "firstNameFieldError.isDisplayed() = " + firstNameFieldError.isDisplayed());
        assertFalse(
                "firstNameFieldError should not be displayed after simply tabbing out of the empty field, having never entered any data.  "
                        + "But we see '" + firstNameFieldError.getText() + "'",
                firstNameFieldError.isDisplayed());
    }

    logger.log(Level.INFO, "Shift tabbing back into the firstNameField ...");
    (new Actions(browser)).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyDown(Keys.SHIFT).perform();

    logger.log(Level.INFO,
            "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath));

    logger.log(Level.INFO, "entering 'asdf' into the firstNameField and then tabbing out of it...");
    firstNameField.sendKeys("asdf");
    firstNameField.sendKeys(Keys.TAB);

    logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value"));
    logger.log(Level.INFO,
            "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath));
    assertTrue("The data 'asdf' should be in the firstNameField after tabbing out of it",
            "asdf".equals(firstNameField.getAttribute("value")));

    logger.log(Level.INFO, "Shift tabbing back into the firstNameField ...");
    (new Actions(browser)).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyUp(Keys.SHIFT).perform();

    firstNameField.click();
    logger.log(Level.INFO,
            "clearing the firstNameField using the BACKSPACE key, and then tabbing out of the firstNameField ...");
    firstNameField.sendKeys(Keys.ARROW_RIGHT, Keys.BACK_SPACE);

    logger.log(Level.INFO, "Waiting for the firstNameField to contain 'asd' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "asd"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, firstNameFieldXpath)) {
            foo = firstNameField.getText();
        }
        logger.log(Level.INFO, "firstNameField.getText() = " + firstNameField.getText());
        assertTrue(
                "firstNameField should contain 'asd', but " + firstNameFieldXpath + " contains '" + foo + "'.",
                false);
    }

    firstNameField.sendKeys(Keys.BACK_SPACE);

    logger.log(Level.INFO, "Waiting for the firstNameField to contain 'as' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "as"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, firstNameFieldXpath)) {
            foo = firstNameField.getText();
        }
        assertTrue(
                "firstNameField should contain 'as', but " + firstNameFieldXpath + " contains '" + foo + "'.",
                false);
    }

    firstNameField.sendKeys(Keys.BACK_SPACE);

    logger.log(Level.INFO, "Waiting for the firstNameField to contain 'a' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "a"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, firstNameFieldXpath)) {
            foo = firstNameField.getText();
        }
        assertTrue("firstNameField should contain 'a', but " + firstNameFieldXpath + " contains '" + foo + "'.",
                false);
    }

    firstNameField.sendKeys(Keys.BACK_SPACE);

    logger.log(Level.INFO, "Waiting for the firstNameField to contain '' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), ""));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, firstNameFieldXpath)) {
            foo = firstNameField.getText();
        }
        assertTrue("firstNameField should contain '', but " + firstNameFieldXpath + " contains '" + foo + "'.",
                false);
    }

    firstNameField.sendKeys(Keys.TAB);

    logger.log(Level.INFO, "Waiting for the firstNameFieldError to contain 'Value is required' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(firstNameFieldErrorXpath),
                "Value is required"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        assertTrue("firstNameFieldError should be visible after tabbing out with no value," + " but "
                + firstNameFieldErrorXpath + " is not visible.", false);
    }

    logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value"));
    assertTrue(
            "The data 'asdf' should no longer be in the firstNameField after clearing it out with BACK_SPACE and then tabbing out.   "
                    + "But we see '" + firstNameField.getAttribute("value") + "'",
            "".equals(firstNameField.getAttribute("value")));
    logger.log(Level.INFO,
            "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath));
    assertTrue(
            "The firstNameFieldError should at least be in the DOM somewhere by this point, but it is not there",
            isThere(browser, firstNameFieldErrorXpath));
    logger.log(Level.INFO, "firstNameFieldError.getText() = " + firstNameFieldError.getText());
    assertTrue("The firstNameFieldError should say 'Value is required'",
            firstNameFieldError.getText().contains("Value is required"));

}

From source file:com.liferay.faces.test.FACES1427PortletTest.java

License:Open Source License

@Test
@RunAsClient/*from ww w.  jav  a  2s. c  o m*/
@InSequence(1300)
public void steps89012() throws Exception {

    if (isThere(browser, errorMessageXpath) && errorMessage.isDisplayed()) {
        return;
    }

    logger.log(Level.INFO, "8: textarea1.getAttribute('value') = " + textarea1.getAttribute("value"));

    // click into textarea1
    textarea1.click();
    Thread.sleep(50);

    // move to the beginning of textarea1
    textarea1.sendKeys(Keys.HOME); // firefox cursor is on the left after the last click, in chromium cursor is on
    // the right of the text ... grr
    Thread.sleep(50);

    // arrow over to the word 'initial'
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);

    // delete the word 'initial'
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);

    // type the word 'subsequent'
    textarea1.sendKeys("subsequent");
    Thread.sleep(50);

    // select the word 'subsequent' ... easier said than done
    logger.log(Level.INFO, "8: textarea1.getAttribute('id') = '" + textarea1.getAttribute("id") + "'");

    logger.log(Level.INFO, "8: before selecting ... selectText.getSelection(id) = "
            + selectText.getSelection(textarea1.getAttribute("id")));
    Thread.sleep(500);

    logger.log(Level.INFO, "8: selectText.getSelection('id', 10, 20) ... ");
    selectText.setSelection(textarea1.getAttribute("id"), 10, 20);
    Thread.sleep(1000);

    logger.log(Level.INFO, "8: after selecting ... selectText.getSelection(id) = "
            + selectText.getSelection(textarea1.getAttribute("id")));
    Thread.sleep(500);

    logger.log(Level.INFO, "8: isThere(browser, bold1Xpath) = " + isThere(browser, bold1Xpath));
    logger.log(Level.INFO, "8: bold1.isDisplayed() = " + bold1.isDisplayed());
    logger.log(Level.INFO, "8: bold1.getAttribute('src') = " + bold1.getAttribute("src"));
    logger.log(Level.INFO, "8: bold1.getLocation() = " + bold1.getLocation());
    logger.log(Level.INFO, "8: clicking the bold1 button ...");

    // click the bold1 button to make the word 'subsequent' bold
    try {
        bold1.click();
    } catch (Exception e) { // apparently things are different in chromium
        logger.log(Level.INFO, "8: e.getMessage() = " + e.getMessage());
        (new Actions(browser)).moveToElement(bold1, 3, 3).click(bold1).build().perform();
        Thread.sleep(500);
        (new Actions(browser)).moveToElement(bold1, 3, 3).click().build().perform();
        Thread.sleep(500);
        (new Actions(browser)).moveToElement(bold1).doubleClick().build().perform();
        Thread.sleep(500);
    }

    Thread.sleep(50);

    // move into iframe1
    logger.log(Level.INFO, "9: clicking into iframe1 ...");
    iframe1.click();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.TAB).perform();
    Thread.sleep(50);

    // arrow over to the word 'initial'
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);

    // delete the word 'initial'
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);

    // type the word 'subsequent'
    (new Actions(browser)).sendKeys("subsequent").perform();
    Thread.sleep(50);

    // select the word 'subsequent' ... easier said than done
    (new Actions(browser)).keyDown(iframe1, Keys.SHIFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT)
            .sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT)
            .sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).keyUp(iframe1, Keys.SHIFT).build()
            .perform();
    Thread.sleep(50);

    // click the bold2 button to make the word 'subsequent' bold
    logger.log(Level.INFO, "9: clicking on the bold button in the second editor ...");
    bold2.click();
    Thread.sleep(50);

    // Why do we need to click the iframe before clicking the submit button?  Who knows?
    iframe1.click();
    Thread.sleep(50);

    // submit the form
    logger.log(Level.INFO, "10: clicking the submit button ...");
    submit.click();
    Thread.sleep(50);

    // log some elements
    logger.log(Level.INFO, "11: comments1Output.getText() = " + comments1Output.getText());
    logger.log(Level.INFO, "12: comments2Output.getText() = " + comments2Output.getText());

    // assert to test
    assertTrue(
            "the submitted value for the FIRST editor should be 'comments1-[b]subsequent[/b]-value', but "
                    + "it is '" + comments1Output.getText() + "'",
            comments1Output.getText().equals("comments1-[b]subsequent[/b]-value"));
    assertTrue(
            "the submitted value for the SECOND editor should be 'comments2-[b]subsequent[/b]-value', but "
                    + "it is '" + comments2Output.getText() + "'",
            comments2Output.getText().equals("comments2-[b]subsequent[/b]-value"));

}

From source file:com.thoughtworks.selenium.webdriven.commands.TypeKeys.java

License:Apache License

@Override
protected Void handleSeleneseCommand(WebDriver driver, String locator, String value) {
    alertOverride.replaceAlertMethod(driver);

    value = value.replace("\\10", Keys.ENTER);
    value = value.replace("\\13", Keys.RETURN);
    value = value.replace("\\27", Keys.ESCAPE);
    value = value.replace("\\38", Keys.ARROW_UP);
    value = value.replace("\\40", Keys.ARROW_DOWN);
    value = value.replace("\\37", Keys.ARROW_LEFT);
    value = value.replace("\\39", Keys.ARROW_RIGHT);

    finder.findElement(driver, locator).sendKeys(value);

    return null;//from w  w  w .jav a 2s .  co  m
}

From source file:com.thoughtworks.selenium.webdriven.commands.TypeKeysTest.java

License:Apache License

@Test
public void substitutesArrowKeys() {
    String expected = newString(Keys.ARROW_DOWN, Keys.ARROW_LEFT, Keys.ARROW_RIGHT, Keys.ARROW_UP);
    String input = "\\40\\37\\39\\38";

    new TypeKeys(new AlertOverrideStub(), elementFinder).apply(null, new String[] { "foo", input });

    verify(element).sendKeys(expected);/* w w w .  j a  v a2 s .  co m*/
}

From source file:com.vaadin.tests.components.grid.basicfeatures.GridColumnHidingTest.java

License:Apache License

@Test
@Ignore//from  w  w  w .ja va 2 s. c  om
public void testNavigationWithHiddenColumns_navigatingOverHiddenColumn_goesToNextVisibleColumn() {
    selectMenuPath("Component", "State", "Width", "1000px");
    toggleHideColumnAPI(2);
    toggleHideColumnAPI(3);
    assertColumnHeaderOrder(0, 1, 4, 5, 6);

    getGridElement().getCell(2, 4).click();
    GridCellElement cell = getGridElement().getCell(2, 4);
    assertTrue(cell.isFocused());

    new Actions(getDriver()).sendKeys(Keys.ARROW_LEFT);
    cell = getGridElement().getCell(2, 1);
    assertTrue(cell.isFocused());

    new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT);
    cell = getGridElement().getCell(2, 4);
    assertTrue(cell.isFocused());
}