Example usage for org.openqa.selenium Keys CONTROL

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

Introduction

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

Prototype

Keys CONTROL

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

Click Source Link

Usage

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 va 2 s  .c om
    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.faces.portal.test.showcase.inputrichtext.InputRichTextTester.java

License:Open Source License

public void runInputRichTextTest(String useCase, String boldOpen, String boldClose, String italicsOpen,
        String italicsClose, String elementToClickXpath) {

    // 1. Navigate to the appropriate "inputRichText" use case.
    BrowserDriver browserDriver = getBrowserDriver();
    navigateToUseCase(browserDriver, "inputRichText", useCase);

    // 2. Verify that the rich text editor is visible.
    WaitingAsserter waitingAsserter = getWaitingAsserter();
    waitingAsserter.assertElementDisplayed(INPUT_RICH_TEXT_DIV_XPATH);

    if (isCheckboxDisplayedAndEnabled(browserDriver, "rendered")) {

        // 3. Click the *Rendered* checkbox.
        browserDriver.clickElement(RENDERED_CHECKBOX_XPATH);

        // 4. Verify that the rich text editor is not visible.
        waitingAsserter.assertElementNotDisplayed(INPUT_RICH_TEXT_DIV_XPATH);

        // 5. Click the *Rendered* checkbox.
        browserDriver.clickElement(RENDERED_CHECKBOX_XPATH);

        // 6. Verify that the rich text editor is visible.
        waitingAsserter.assertElementDisplayed(INPUT_RICH_TEXT_DIV_XPATH);
    }/*from  w  w w.j  ava2 s  .c o  m*/

    if (isCheckboxDisplayedAndEnabled(browserDriver, "required")) {

        // 7. Click the *Submit* button.
        browserDriver.clickElement(elementToClickXpath);

        // 8. Verify that no error messages are shown since the rich text editor is not a required field.
        waitingAsserter.assertElementNotDisplayed(valueIsRequiredError1Xpath);

        // 9. Click the *Required* checkbox.
        browserDriver.clickElement(requiredCheckbox1Xpath);

        // 10. Click the *Submit* button.
        browserDriver.clickElement(elementToClickXpath);

        // 11. Verify that a "Value is required." error message appears.
        waitingAsserter.assertElementDisplayed(valueIsRequiredError1Xpath);
    }

    // 12. Enter "Hello to the whole World!" into the rich text editor.
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);

    String text = "Hello to the whole World!";
    browserDriver.sendKeysToElement(BODY_XPATH, text);

    // 13. Click the *Submit* button.
    submitRichText(browserDriver, elementToClickXpath, 1, text);

    // 14. Verify that "Hello to the whole World!" appears in the *Model Value*.
    waitingAsserter.assertTextPresentInElement(text, modelValue1Xpath);

    // 15. Verify that the "Value is required." error message does not appear.
    waitingAsserter.assertElementNotDisplayed(valueIsRequiredError1Xpath);

    // 16. Select the text "lo to the wh" in the rich text editor.
    // 17. Press Ctrl + b (or Cmd + b) to bold the text.
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);

    String boldSelection = "lo to the wh";
    selectTextAndSendKeys(browserDriver, text, boldSelection, Keys.CONTROL, Keys.COMMAND, "b");

    // 18. Select the text "o the whole Wor" in the rich text editor.
    // 19. Press Ctrl + i (or Cmd + i) to italicize the text.
    String italicizedSelection = "o the whole Wor";
    selectTextAndSendKeys(browserDriver, text, italicizedSelection, Keys.CONTROL, Keys.COMMAND, "i");

    // 20. Click the *Submit* button.
    String expectedFormattedText = "Hel<strong>lo t<em>o the wh</em></strong><em>ole Wor</em>ld!";
    expectedFormattedText = expectedFormattedText.replace("<strong>", boldOpen).replace("</strong>", boldClose)
            .replace("<em>", italicsOpen).replace("</em>", italicsClose);
    submitRichText(browserDriver, elementToClickXpath, 1, expectedFormattedText);

    // 21. Verify that "Hel<strong>lo t<em>o the wh</em></strong><em>ole Wor</em>ld!" appears (with the appropriate
    // markup for the current use-case) in the *Model Value*.
    waitingAsserter.assertTextPresentInElement(expectedFormattedText, modelValue1Xpath);

    // 22. Verify that the "Value is required." error message does not appear.
    waitingAsserter.assertElementNotDisplayed(valueIsRequiredError1Xpath);
}

From source file:com.liferay.faces.portal.test.showcase.inputrichtext.InputRichTextValidationTester.java

License:Open Source License

@Test
public void runInputRichTextValidationTest() {

    // 1. Navigate to the "inputRichText" "Validation" use case.
    BrowserDriver browserDriver = getBrowserDriver();
    navigateToUseCase(browserDriver, "inputRichText", "validation");

    // 2. Enter "123456789" into the rich text editor.
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);

    StringBuilder stringBuilder = new StringBuilder();

    for (int i = 1; i < MIN_PLAIN_TEXT_CHARS; i++) {
        stringBuilder.append(i % 10);/*from   ww w .  java 2 s.c  o  m*/
    }

    browserDriver.sendKeysToElement(BODY_XPATH, stringBuilder.toString());

    // 3. Click the *Submit* button.
    browserDriver.getWebDriver().switchTo().parentFrame();
    browserDriver.clickElement(submitButton1Xpath);

    // 4. Verify that the "Length is less than allowable minimum of '10'" feedback message appears.
    WaitingAsserter waitingAsserter = getWaitingAsserter();
    waitingAsserter.assertElementDisplayed(LESS_THAN_MIN_CHARS_ERROR_XPATH);

    // 5. Verify that nothing appears in the model value since the submitted value is invalid.
    waitingAsserter.assertTextNotPresentInElement(stringBuilder.toString(), modelValue1Xpath, false);

    // 6. Navigate to the "inputRichText" "Validation" use case to reset the rich text value.
    navigateToUseCase(browserDriver, "inputRichText", "validation");

    // 7. Enter "123456789a" into the rich text editor.
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);
    stringBuilder.append("a");
    browserDriver.sendKeysToElement(BODY_XPATH, stringBuilder.toString());

    // 8. Click the *Submit* button.
    submitRichText(browserDriver, submitButton1Xpath, 1, stringBuilder.toString());

    // 9. Verify that the "Length is less than allowable minimum of '10'" feedback message does not appear.
    waitingAsserter.assertElementNotDisplayed(LESS_THAN_MIN_CHARS_ERROR_XPATH);

    // 10. Verify that "123456789a" appears in the model value.
    waitingAsserter.assertTextPresentInElement(stringBuilder.toString(), modelValue1Xpath);

    // 11. Navigate to the "inputRichText" "Validation" use case to reset the rich text value.
    navigateToUseCase(browserDriver, "inputRichText", "validation");

    // 12. Enter the maximum number of characters (144) into the rich text editor.
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);
    stringBuilder.setLength(0);

    for (int i = 0; i < MAX_PLAIN_TEXT_CHARS; i++) {

        if (i == 0) {
            stringBuilder.append("b");
        } else {
            stringBuilder.append(i % 10);
        }
    }

    browserDriver.sendKeysToElement(BODY_XPATH, stringBuilder.toString());

    // 13. Click the *Submit* button.
    submitRichText(browserDriver, submitButton1Xpath, 1, stringBuilder.toString());

    // 14. Verify that the "Length is greater than allowable maximum of '144'" feedback message does not appear.
    waitingAsserter.assertElementNotDisplayed(GREATER_THAN_MAX_CHARS_ERROR_XPATH);

    // 15. Verify that the 144 submitted characters appear in the model value.
    waitingAsserter.assertTextPresentInElement(stringBuilder.toString(), modelValue1Xpath);

    //J-
    // 16. Select the first character in the rich text editor.
    // 17. Press Ctrl + b (Cmd + b on Mac) to bold the first character.
    //J+
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);

    selectTextAndSendKeys(browserDriver, stringBuilder.toString(), "b", Keys.CONTROL, Keys.COMMAND, "b");

    // 18. Click the *Submit* button.
    String boldModelValue = stringBuilder.toString().replace("b", "<strong>b</strong>");
    submitRichText(browserDriver, submitButton1Xpath, 1, boldModelValue);

    // 19. Verify that the 144 submitted characters appear in the model value with the first character surrounded by
    // <strong> tags.
    waitingAsserter.assertTextPresentInElement(boldModelValue, modelValue1Xpath);

    // 20. Verify that the "Length is greater than allowable maximum of '144'" feedback message does not appear.
    waitingAsserter.assertElementNotDisplayed(GREATER_THAN_MAX_CHARS_ERROR_XPATH);

    // 21. Navigate to the "inputRichText" "Validation" use case to reset the rich text value.
    navigateToUseCase(browserDriver, "inputRichText", "validation");

    // 22. Enter the maximum number of characters (144) plus one "a" into the rich text editor.
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);
    stringBuilder.append("a");
    browserDriver.sendKeysToElement(BODY_XPATH, stringBuilder.toString());

    // 23. Click the *Submit* button.
    submitRichText(browserDriver, submitButton1Xpath, 1, stringBuilder.toString());

    // 24. Verify that the "Length is greater than allowable maximum of '144'" feedback message appears.
    waitingAsserter.assertElementDisplayed(GREATER_THAN_MAX_CHARS_ERROR_XPATH);

    // 25. Verify that nothing appears in the model value since the submitted value is invalid.
    waitingAsserter.assertTextNotPresentInElement(stringBuilder.toString(), modelValue1Xpath, false);
}

From source file:com.machinepublishers.jbrowserdriver.Robot.java

License:Apache License

void keysType(final CharSequence... charsList) {
    for (CharSequence chars : charsList) {
        if (Util.KEYBOARD_DELETE.equals(chars.toString())) {
            keysTypeHelper(Keys.chord(Keys.CONTROL, "a"));
            keysTypeHelper(Keys.BACK_SPACE.toString());
        } else {/*from  ww  w. j av  a2  s  .  c o m*/
            keysTypeHelper(chars);
        }
    }
}

From source file:com.mgmtp.jfunk.web.util.WebDriverTool.java

License:Apache License

/**
 * Opens a new window and switches to it. The window to switch to is determined by diffing
 * the given {@code existingWindowHandles} with the current ones. The difference must be
 * exactly one window handle which is then used to switch to.
 *
 * @param openClickBy//from w  w  w.  ja  v a2s. co m
 *            identifies the element to click on in order to open the new window
 * @param timeoutSeconds
 *            the timeout in seconds to wait for the new window to open
 * @return the handle of the window that opened the new window
 */
public String openNewWindow(final By openClickBy, final long timeoutSeconds) {
    checkTopmostElement(openClickBy);
    return openNewWindow(() -> sendKeys(openClickBy, Keys.chord(Keys.CONTROL, Keys.RETURN)), timeoutSeconds);
}

From source file:com.mkl.websuites.internal.command.impl.key.PressCommand.java

License:Apache License

private Keys keyFromModifier(String key) {
    switch (key) {
    case "CTRL":
        return Keys.CONTROL;
    case "ALT":
        return Keys.ALT;
    case "SHIFT":
        return Keys.SHIFT;
    default://from ww  w  . ja  v a 2s  .  c  o  m
        return null;
    }
}

From source file:com.nabla.project.fronter.selenium.tests.helper.SeleniumHelper.java

License:Open Source License

public static void testRowSelectionUsingControlKey(final List<WebElement> tableRowsInput,
        final List<WebElement> tableRowsOutput, final long expectedRows, final WebDriver driver) {

    // List<WebElement> tableRowsInput = driver.findElements(By.xpath("//table[@class='myDataTbl']/tbody/tr"));
    // Selected Row Table shows two rows selected
    // List<WebElement> tableRowsOutput = driver.findElements(By.xpath("//div[@class='icePnlGrp exampleBox']/table[@class='myDataTbl']/tbody/tr"));

    // Select second and fourth row from Table using Control Key.
    // Row Index start at 0
    final Actions builder = new Actions(driver);
    builder.click(tableRowsInput.get(1)).keyDown(Keys.CONTROL).click(tableRowsInput.get(3)).keyUp(Keys.CONTROL)
            .build().perform();//from   w  w  w  .  java 2  s  . co  m

    // Verify Selected Row Table shows X rows selected
    Assert.assertEquals(expectedRows, tableRowsOutput.size());

}

From source file:com.opera.core.systems.DriverKeysTest.java

License:Apache License

@Test
public void testHoldControl() {
    // Control + A
    new Actions(driver).sendKeys("a" + Keys.CONTROL + "a" + Keys.CONTROL + "bc").build().perform();
    assertEquals("bc", fieldOne.getAttribute("value"));
}

From source file:com.opera.core.systems.DriverKeysTest.java

License:Apache License

@Test
public void testMultipleModifiers() throws Exception {
    new Actions(driver).sendKeys("abc defghij").sendKeys(Keys.CONTROL + "" + Keys.LEFT_SHIFT + Keys.LEFT)
            .sendKeys(Keys.BACK_SPACE).build().perform();

    assertEquals("abc ", fieldOne.getAttribute("value"));
}

From source file:com.opera.core.systems.DriverKeysTest.java

License:Apache License

@Test
public void testCopyPaste() throws Exception {
    new Actions(driver).sendKeys("hello world").sendKeys(Keys.CONTROL + "a").sendKeys(Keys.CONTROL + "c")
            .sendKeys(fieldTwo, Keys.CONTROL + "v").build().perform();

    assertEquals("hello world", fieldTwo.getAttribute("value"));
}