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.cognifide.qa.bb.test.actions.BobcatActionsTest.java

License:Apache License

@Test
public void shouldBeBlankAfterClear() {
    //given/*from w  w w  . j  av  a  2  s.  com*/
    shouldContainTextAfterTextSendKeys();

    //when
    actions.sendKeys(inputElement, Keys.chord(Keys.CONTROL, "a")).sendKeys(Keys.BACK_SPACE).perform();

    //then
    assertThat(getTextFromInputElement()).isEmpty();
}

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));
    }/*from  w w w .  ja va2  s .  c  om*/

    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/*from  w w  w  . j a  va  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.example.selenium.action.TableRowSelection.java

@Test
public void testRowSelectionUsingControlKey() throws InterruptedException {

    List<WebElement> tableRows = driver.findElements(By.xpath("//table[@id='dataTables-example']/tbody/tr"));

    //Select second and fourth row from table using Control Key.
    //Row Index start at 0
    Actions builder = new Actions(driver);
    builder.click(tableRows.get(0)).keyDown(Keys.CONTROL).click(tableRows.get(2)).keyUp(Keys.CONTROL).build()
            .perform();//from w  w w.java2s  . com
    Thread.sleep(3000);

}

From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java

License:Apache License

/**
 * @exception Exception If the test fails
 *///from   w w w .j a  v a 2 s .  c om
@Test
@BuggyWebDriver({ IE, FF })
public void ctrlClick() throws Exception {
    final String html = "<html><head><title>First</title></head><body>\n" + "<a href='" + URL_SECOND
            + "'>Click Me</a>\n" + "</form></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, "<head><title>Second</title>");
    final WebDriver driver = loadPage2(html);

    final WebElement link = driver.findElement(By.linkText("Click Me"));

    final String originalTitle = driver.getTitle();

    final int windowsSize = driver.getWindowHandles().size();

    new Actions(driver).moveToElement(link).keyDown(Keys.CONTROL).click().keyUp(Keys.CONTROL).perform();

    assertEquals("Should have opened a new window", windowsSize + 1, driver.getWindowHandles().size());
    assertEquals("Should not have navigated away", originalTitle, driver.getTitle());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlSelect2Test.java

License:Apache License

/**
 * @exception Exception If the test fails
 *//*from   ww w.ja va 2s. c  o m*/
@Test
@BuggyWebDriver({ FF, IE })
public void controlClick() throws Exception {
    final String html = "<html><head><title>foo</title></head><body>\n"
            + "<form id='form1'><select name='select1' multiple>\n"
            + "  <option value='option1'>Option1</option>\n" + "  <option value='option2'>Option2</option>\n"
            + "  <option value='option3' selected='selected'>Option3</option>\n"
            + "  <option value='option4'>Option4</option>\n" + "</select>\n"
            + "<input type='submit' name='button' value='foo'/>\n" + "</form></body></html>";

    final WebDriver driver = loadPage2(html);

    final List<WebElement> options = driver.findElements(By.tagName("option"));

    final Actions actions = new Actions(driver);
    final Action selectThreeOptions = actions.click(options.get(1)).keyDown(Keys.CONTROL).click(options.get(3))
            .keyUp(Keys.CONTROL).build();

    selectThreeOptions.perform();

    assertFalse(options.get(0).isSelected());
    assertTrue(options.get(1).isSelected());
    assertFalse(options.get(2).isSelected());
    assertTrue(options.get(3).isSelected());
}

From source file:com.giri.target.svr.cmd.KeyCommandProcessor.java

License:Open Source License

public CharSequence getKey(String keystr) throws Exception {
    CharSequence keySeq = keystr;
    try {//ww  w. j a  v a 2 s.c o m
        keySeq = Keys.valueOf(keystr);
    } catch (IllegalArgumentException e) {
        // looking for some short keys, 
        // CTRL - CONTROL
        // DEL - DELETE
        //ESCAPE
        if (keystr.indexOf('+') != -1 && keystr.length() > 1) {
            String[] keyStrs = keystr.split("\\+");
            StringBuilder sb = new StringBuilder();
            if (keyStrs != null && keyStrs.length > 0) {
                // pass for number check

                CharSequence[] kf = new CharSequence[keyStrs.length];
                int cnt = 0;
                for (String string : keyStrs) {
                    CharSequence keys = getKey(string);
                    keys = (keys == null ? string : keys);
                    kf[cnt] = keys;

                    if (cnt != 0) {
                        sb.append(" + ");
                    }
                    //                  if(keys == null){
                    //                     throw new Exception("No such key '"+string+"'");
                    //                  }
                    sb.append(keys);

                    cnt++;
                }
                keySeq = Keys.chord(kf);
            }

            System.out.println("Multikeys [" + sb.toString() + "]: " + keySeq);
        } else if ("CTRL".equalsIgnoreCase(keystr)) {
            keySeq = Keys.CONTROL;
        } else if ("DEL".equalsIgnoreCase(keystr)) {
            keySeq = Keys.DELETE;
        } else if ("EQ".equalsIgnoreCase(keystr)) {
            keySeq = Keys.EQUALS;
        } else if ("ESC".equalsIgnoreCase(keystr)) {
            keySeq = Keys.ESCAPE;
        } else {
            // check if its number key
            try {
                int num = Integer.parseInt(keystr);
                if (num >= 0 && num <= 9) {
                    keySeq = Keys.valueOf("NUMPAD" + num);
                }
            } catch (Exception e1) {
            }
        }
    }
    return keySeq;
}

From source file:com.hp.test.framework.jelly.PressKeyonBrowserTag.java

@Override
public void doTag(XMLOutput arg0) throws MissingAttributeException, JellyTagException {
    logger.info("Started Execution of PressKeyonBrowserTag");
    WebDriver driver = getSelenium();//from   w ww  .j  a  va2 s.com
    try {
        Actions action = new Actions(driver);
        if (value.contains("+")) {

            String[] temp = value.split("\\+");
            switch (temp[0].toUpperCase()) {
            case "CONTROL":
                action.sendKeys(Keys.chord(Keys.CONTROL, temp[1].toLowerCase())).build().perform();
                break;
            case "ALT":
                action.sendKeys(Keys.chord(Keys.ALT, temp[1].toLowerCase())).build().perform();
                break;
            }
        } else {
            action.sendKeys(Keys.valueOf(value)).build().perform();
        }
    } catch (Exception e) {
        logger.error("Exception in the Pres Key on Browser" + "\n" + e.getMessage());
    }
    logger.info("End of Execution of PressKeyonBrowserTag");
}

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

License:Open Source License

/**
 * Copy text into clipboard from the current cursor position. Applicable
 * only for editable fields i.e textbox, textarea etc. First it will click
 * on that element and then select all text and copy into clipboard.
 * //w  w w.j  a v  a2s.  com
 * @return
 */
public void copyTextToClipboard(int numRetries) {
    try {
        for (int i = 0; i < 5; i++) {
            try {
                WebElement webElem = findElement(numRetries);
                webElem.click();
                Actions webActions = new Actions(browser.getSeleniumWebDriver());
                webActions.sendKeys(Keys.CONTROL + "a").sendKeys(Keys.CONTROL + "c");
                break;
            } catch (MoveTargetOutOfBoundsException | ElementNotVisibleException ex) {
                browser.waitForSeconds(2);
            }
        }
    } catch (Throwable th) {
        Assert.fail("Failed to copy contents into clipboard. Element '" + domObject.getDisplayName() + "'.",
                th);
    }
}

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

License:Open Source License

/**
 * Replace the content of the element with the clipboard contents.
 * Applicable only for editable fields i.e textbox, textarea etc.
 * /*from  w w  w  .  ja v a2s.  co m*/
 * @return
 */
public void pasteTextFromClipboard(int numRetries) {
    try {
        for (int i = 0; i < 5; i++) {
            try {
                WebElement webElem = findElement(numRetries);
                webElem.click();
                Actions webActions = new Actions(browser.getSeleniumWebDriver());
                webActions.sendKeys(Keys.CONTROL + "a").sendKeys(Keys.CONTROL + "v").build().perform();
                break;
            } catch (MoveTargetOutOfBoundsException | ElementNotVisibleException ex) {
                browser.waitForSeconds(2);
            }
        }
    } catch (Throwable th) {
        Assert.fail("Failed to paste clipboard contents into field '" + domObject.getDisplayName() + "'.", th);
    }
}