Example usage for org.openqa.selenium Keys SPACE

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

Introduction

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

Prototype

Keys SPACE

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

Click Source Link

Usage

From source file:com.vaadin.v7.tests.components.grid.GridCustomSelectionModelTest.java

License:Apache License

@Test
public void testCustomSelectionModel() {
    setDebug(true);/*from   ww w.  ja  v a 2 s.c o m*/
    openTestURL();

    GridElement grid = $(GridElement.class).first();
    GridCellElement cell = grid.getCell(0, 0);
    assertTrue("First column of Grid should not have an input element",
            cell.findElements(By.className("input")).isEmpty());

    assertFalse("Row should not be selected initially", grid.getRow(0).isSelected());

    cell.click(5, 5);
    assertTrue("Click should select row", grid.getRow(0).isSelected());
    cell.click(5, 5);
    assertFalse("Click should deselect row", grid.getRow(0).isSelected());

    grid.sendKeys(Keys.SPACE);
    assertTrue("Space should select row", grid.getRow(0).isSelected());
    grid.sendKeys(Keys.SPACE);
    assertFalse("Space should deselect row", grid.getRow(0).isSelected());

    assertNoErrorNotifications();
}

From source file:com.watchrabbit.scanner.supervisor.service.AttackerServiceImpl.java

License:Apache License

private void fillCheckbox(Field field) {
    field.getField().sendKeys(Keys.SPACE);
}

From source file:contentspeed.CosCumparaturi.java

void findClickTermeni() {

    driver.findElement(termeni).sendKeys(Keys.SPACE);

}

From source file:org.auraframework.components.ui.inputDate.BaseInputDateUITester.java

License:Apache License

private String pageUpDownHelper(int iterCondition, String keyString) {
    WebDriver driver = getDriver();//from  www  .j  ava 2s  .co  m
    // Test Begins
    // Making sure the textBox is empty so we always start at the same date
    WebElement element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    element.clear();
    element.sendKeys(TEST_DATE_TO_USE);

    // Grabbing the Date Icon and click on it to open the calendar
    element = findDomElement(By.cssSelector(DATE_ICON_SEL));
    element.click();

    String classOfActiveElem = "" + auraUITestingUtil.getEval(CLASSNAME);
    element = findDomElement(By.cssSelector("a[class*='" + classOfActiveElem + "']"));

    element = loopThroughKeys(element, driver, keyString, iterCondition, ARIA_SELECTED_SEL,
            "Shift+Page Up/Down");

    // Selecting the date that we are on to get the value and compare it to what it should be
    element.sendKeys(Keys.SPACE);

    // Setting the input box in focus to get its value
    element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));

    // Checking if the values are equal
    return element.getAttribute("value");
}

From source file:org.auraframework.components.ui.inputDate.BaseInputDateUITester.java

License:Apache License

private String homeEndButtonHelper(String initDate, Keys buttonToPress) {
    // Getting the input box, making sure it is clear, and sending in the the starting date
    WebElement element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    element.clear();//from   w  ww  .  jav  a 2 s.  c  o  m
    element.sendKeys(initDate);

    // Opening the calendar icon to grab the date we are looking for
    element = findDomElement(By.cssSelector(DATE_ICON_SEL));
    element.click();

    // Grabbing the correct focus cell date
    element = findDomElement(By.cssSelector(SELECTED_DATE));

    // Pressing the home or End button and grabbing the associated date
    element.sendKeys(buttonToPress);
    element = findDomElement(By.cssSelector(ARIA_SELECTED_SEL));

    // Clicking on that element to compare it to the date we should receive
    element.sendKeys(Keys.SPACE);

    // Repointing to the InputTextBox
    element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));

    // Making sure they are equal
    return element.getAttribute("value");
}

From source file:org.auraframework.components.ui.inputDate.BaseInputDateUITester.java

License:Apache License

@ExcludeBrowsers({ BrowserType.ANDROID_PHONE, BrowserType.ANDROID_TABLET, BrowserType.IPAD,
        BrowserType.IPHONE })/* ww  w . j  a  v  a 2s .c  o m*/
public void testDateWithOneArrow() throws Exception {
    open(URL);
    WebDriver driver = getDriver();

    // Test Begins
    // Getting the calendar Icon
    WebElement element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    element.click();
    element.sendKeys("2013-10-01");

    element = findDomElement(By.cssSelector(DATE_ICON_SEL));
    element.click();

    String classOfActiveElem = "" + auraUITestingUtil.getEval(CLASSNAME);

    element = findDomElement(By.cssSelector("a[class*='" + classOfActiveElem + "']"));

    // Loop through 355 days
    element = loopThroughKeys(element, driver, "" + Keys.ARROW_RIGHT, 151, ARIA_SELECTED_SEL, "Arrow-Right ");

    element.sendKeys(Keys.SPACE);

    element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    assertEquals("Dates do not match up", "2014-03-01", element.getAttribute("value"));
}

From source file:org.auraframework.components.ui.inputDate.BaseInputDateUITester.java

License:Apache License

@ExcludeBrowsers({ BrowserType.ANDROID_PHONE, BrowserType.ANDROID_TABLET, BrowserType.IPAD,
        BrowserType.IPHONE })/*w  w  w  .  j a  v a  2s .  c o m*/
public void testLeftAndRightArrows() throws Exception {
    // Increase day in month by 1
    open(URL);
    WebDriver driver = getDriver();

    WebElement element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    element.click();
    element.sendKeys(TEST_DATE_TO_USE);
    // Test Begins
    // Grab calendar Icon
    element = findDomElement(By.cssSelector(DATE_ICON_SEL));
    element.click();

    // Find todays date, which should be focused
    String classOfActiveElem = "" + auraUITestingUtil.getEval(CLASSNAME);
    element = findDomElement(By.cssSelector("a[class*='" + classOfActiveElem + "']"));

    // Move from todays date, to the todays date +41
    element = loopThroughKeys(element, driver, "" + Keys.ARROW_RIGHT, 41, ARIA_SELECTED_SEL,
            "Arrow-Right key ");

    // Move from today (date+41), to the todays date+1
    element = loopThroughKeys(element, driver, "" + Keys.ARROW_LEFT, 40, ARIA_SELECTED_SEL, "Arrow-Left key");

    // Select element
    element.sendKeys(Keys.SPACE);

    // Focus on the input box and get its value
    element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    assertEquals("Next day was not correctly found", "2013-04-16", element.getAttribute("value"));
}

From source file:org.auraframework.components.ui.inputDate.BaseInputDateUITester.java

License:Apache License

@ExcludeBrowsers({ BrowserType.ANDROID_PHONE, BrowserType.ANDROID_TABLET, BrowserType.IPAD,
        BrowserType.IPHONE })/*from   w  w  w  . ja  va 2s  .  c  o m*/
public void testUpAndDownArrows() throws Exception {

    open(URL);
    WebDriver driver = getDriver();

    // Start at specific date
    WebElement element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    element.click();
    element.sendKeys(TEST_DATE_TO_USE);

    // Test Begins
    // Select the calendar Icon
    element = findDomElement(By.cssSelector(DATE_ICON_SEL));
    element.click();

    // Find todays date, which should be focused
    String classOfActiveElem = "" + auraUITestingUtil.getEval(CLASSNAME);
    element = findDomElement(By.cssSelector("a[class*='" + classOfActiveElem + "']"));

    // Move 4 months up
    element = loopThroughKeys(element, driver, "" + Keys.ARROW_UP, 4, ARIA_SELECTED_SEL, "Arrow-Up key");

    // Move 4 months down
    element = loopThroughKeys(element, driver, "" + Keys.ARROW_DOWN, 4, ARIA_SELECTED_SEL, "Arrow-Down key");

    // Focus should be back on todays date
    element.sendKeys(Keys.SPACE);

    // Select the input text box and get its value for comparison
    element = findDomElement(By.cssSelector(DATE_INPUT_BOX_SEL));
    assertEquals("Moving dates using arrows has not brought us to todays date", TEST_DATE_TO_USE,
            element.getAttribute("value"));
}

From source file:org.auraframework.components.ui.menu.MenuUITest.java

License:Apache License

private void testActionMenuViaKeyboardInteractionForApp(String appName)
        throws MalformedURLException, URISyntaxException {
    open(appName);//from   w  w w  .j a  v a  2  s.  com
    WebDriver driver = this.getDriver();
    String label = "trigger";
    String menuName = "actionMenu";
    String menuItem1 = "actionItem1";
    String menuItem3 = "actionItem3";
    String menuItem4 = "actionItem4";
    WebElement menuLabel = driver.findElement(By.className(label));
    WebElement actionMenu = driver.findElement(By.className(menuName));
    WebElement actionItem1 = driver.findElement(By.className(menuItem1));
    WebElement actionItem1Element = actionItem1.findElement(By.tagName("a"));
    WebElement actionItem3 = driver.findElement(By.className(menuItem3));
    WebElement actionItem3Element = actionItem3.findElement(By.tagName("a"));
    WebElement actionItem4 = driver.findElement(By.className(menuItem4));
    WebElement actionItem4Element = actionItem4.findElement(By.tagName("a"));

    // click on menu list
    menuLabel.click();
    // check menu list is visible after the click
    assertTrue("Menu list should be visible", actionMenu.getAttribute("class").contains("visible"));

    // default focus on action item1
    assertEquals("Focus should be on actionItem1", actionItem1Element.getText(),
            auraUITestingUtil.getActiveElementText());

    // press down key twice
    actionItem1Element.sendKeys(Keys.DOWN, Keys.DOWN);

    // verify focus on action item3
    auraUITestingUtil.setHoverOverElement(menuItem3);
    assertEquals("Focus should be on actionItem3", actionItem3Element.getText(),
            auraUITestingUtil.getActiveElementText());

    actionItem3.click();
    assertEquals("Item3 unchecked after pressing Enter key", "Inter Milan", menuLabel.getText());

    menuLabel.click();
    // focus on action item4
    auraUITestingUtil.setHoverOverElement(menuItem4);
    assertEquals("Focus should be on actionItem4", actionItem4Element.getText(),
            auraUITestingUtil.getActiveElementText());

    actionItem4Element.sendKeys(Keys.UP);
    // verify focus on action item3
    assertEquals("Focus should be on actionItem3", actionItem3Element.getText(),
            auraUITestingUtil.getActiveElementText());

    // press space key and check if item3 got selected
    actionItem3Element.sendKeys(Keys.SPACE);
    assertEquals("Item3 not selected after pressing space key", "Inter Milan", menuLabel.getText());

    menuLabel.click();
    assertTrue("Menu list should be visible", actionMenu.getAttribute("class").contains("visible"));
    auraUITestingUtil.setHoverOverElement(menuItem1);
    actionItem1Element.sendKeys(Keys.ESCAPE);
    assertFalse("Menu list should not be visible", actionMenu.getAttribute("class").contains("visible"));
}

From source file:org.auraframework.components.ui.menu.MenuUITest.java

License:Apache License

private void testMenuCheckboxForApp(String appName) throws MalformedURLException, URISyntaxException {
    open(appName);// www  .  j  a v  a 2s . co m
    WebDriver driver = this.getDriver();
    String label = "checkboxMenuLabel";
    String menuName = "checkboxMenu";
    String menuItem3 = "checkboxItem3";
    String menuItem4 = "checkboxItem4";
    String globalIdItem3 = auraUITestingUtil.getCmpGlobalIdGivenElementClassName(menuItem3);
    String globalIdItem4 = auraUITestingUtil.getCmpGlobalIdGivenElementClassName(menuItem4);
    String disableValueM4Exp = auraUITestingUtil.getValueFromCmpExpression(globalIdItem4, "v.disabled");
    String selectedValueM4Exp = auraUITestingUtil.getValueFromCmpExpression(globalIdItem4, "v.selected");
    String selectedValueM3Exp = auraUITestingUtil.getValueFromCmpExpression(globalIdItem3, "v.selected");
    WebElement menuLabel = driver.findElement(By.className(label));
    WebElement menu = driver.findElement(By.className(menuName));
    WebElement item3 = driver.findElement(By.className(menuItem3));
    WebElement item3Element = item3.findElement(By.tagName("a"));
    WebElement item4 = driver.findElement(By.className(menuItem4));
    WebElement item4Element = item4.findElement(By.tagName("a"));
    WebElement button = driver.findElement(By.className("checkboxButton"));
    WebElement result = driver.findElement(By.className("result"));

    // check for default label present
    assertEquals("label is wrong", "NFC West Teams", menuLabel.getText());
    assertFalse("Default: CheckboxMenu list should not be visible",
            menu.getAttribute("class").contains("visible"));

    // click on label
    menuLabel.click();

    // verify menu list is visible
    assertTrue("CheckboxMenu list should be visible", menu.getAttribute("class").contains("visible"));

    // verify aria attribute item4 which is used for accessibility is disabled and selected
    assertTrue("Item4 aria attribute should be disabled",
            Boolean.valueOf(item4Element.getAttribute("aria-disabled")));
    assertTrue("Item4 aria attribute should be selected",
            Boolean.valueOf(item4Element.getAttribute("aria-checked")));

    // verify item4 is disabled and selected

    assertTrue("Item4 should be disabled", (Boolean) auraUITestingUtil.getEval(disableValueM4Exp));
    assertTrue("Item4 should be selected", (Boolean) auraUITestingUtil.getEval(selectedValueM4Exp));

    // click on item4
    item4Element.click();
    assertTrue("Item4 aria attribute should be Selected even when clicked",
            Boolean.valueOf(item4Element.getAttribute("aria-checked")));
    assertTrue("Item4 should be Selected even when clicked",
            (Boolean) auraUITestingUtil.getEval(selectedValueM4Exp));

    assertFalse("default: Item3 aria attribute should be Uncheked",
            Boolean.valueOf(item3Element.getAttribute("aria-checked")));
    assertFalse("default: Item3 should be Uncheked", (Boolean) auraUITestingUtil.getEval(selectedValueM3Exp));

    // click on item3
    item3Element.click();
    assertTrue("Item3 aria attribute should be Selected after the click",
            Boolean.valueOf(item3Element.getAttribute("aria-checked")));
    assertTrue("Item3 should be Selected after the click",
            (Boolean) auraUITestingUtil.getEval(selectedValueM3Exp));

    // click on item3 again
    auraUITestingUtil.pressEnter(item3Element);
    // verify not selected
    assertFalse("Item3 aria attribute should be Uncheked after Pressing Enter",
            Boolean.valueOf(item3Element.getAttribute("aria-checked")));
    assertFalse("Item3 should be Uncheked after Pressing Enter",
            (Boolean) auraUITestingUtil.getEval(selectedValueM3Exp));

    item3Element.sendKeys(Keys.SPACE);
    assertTrue("Item3 aria attribute should be checked after Pressing Space",
            Boolean.valueOf(item3Element.getAttribute("aria-checked")));
    assertTrue("Item3 should be checked after Pressing Space",
            (Boolean) auraUITestingUtil.getEval(selectedValueM3Exp));

    // check if focus changes when you use up and down arrow using keyboard
    item3Element.sendKeys(Keys.DOWN);
    assertEquals("Focus should be on item 4", item4Element.getText(), auraUITestingUtil.getActiveElementText());
    item4Element.sendKeys(Keys.UP);
    assertEquals("Focus should be back to item 3", item3Element.getText(),
            auraUITestingUtil.getActiveElementText());

    // press Tab to close to menu
    item3Element.sendKeys(Keys.TAB);

    // verify menu not visible
    assertFalse("CheckboxMenu list should not be visible after escape",
            menu.getAttribute("class").contains("visible"));

    // click on submit button and verify the results
    assertEquals("label value should not get updated", "NFC West Teams", menuLabel.getText());
    button.click();
    assertEquals("Checkbox items selected are not correct", "St. Louis Rams,Arizona Cardinals",
            result.getText());
}