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:StoryKeyboardShortcutTests.java

@Test
public void storyFirstTest() throws InterruptedException {

    //1. Go to story site
    driver.get(/*from  w  w  w .  jav a 2 s  . com*/
            "http://tanveer-pc:9724/web/story/story.html?debug&storyhub=tanveer-pc&gh=Guest/@tanveer-pc&pilot=tanveer-pc&preview=tanveer-pc&mediaservice=tanveer-pc");
    //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']")));

    //2. Close the license popup
    WebElement okButton = driver.findElement(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']"));
    okButton.click();

    //Click on Media tab
    WebElement uploadButton = driver.findElement(
            By.xpath("html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/table/tbody/tr/td"));
    uploadButton.click();

    //Click on video tab
    WebElement videoTab = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[1]/div/div/div/table[1]/tbody[2]/tr[1]/td[1]/div/div/div[2]"));
    videoTab.click();
    WebElement searchText = driver.findElement(By.id("isc_30"));
    searchText.sendKeys("SSS_2477_01.mov");

    Thread.sleep(5000);
    WebElement selectVideo = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div[1]/div[3]"));

    selectVideo.click();

    WebElement selectVideo1 = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div[1]/div[3]"));
    selectVideo1.click();

    Thread.sleep(2000);
    WebElement timeLine = driver.findElement(By.cssSelector("svg[id=multimedia_ClearInOut]"));
    timeLine.click();

    Thread.sleep(2000);
    int xp1 = 0;
    WebElement testtimecode1 = driver.findElement(By.xpath("//*[contains(text(),'00:0" + xp1 + ":')]"));
    final String starttime = testtimecode1.getText();

    Actions action = new Actions(driver);
    action.sendKeys(Keys.SPACE).build().perform();
    System.out.println(testtimecode1.getText());

    int ourtime = 9000;
    Thread.sleep(ourtime);
    int xp = (ourtime - 1000) / 1000;
    action.sendKeys(Keys.SPACE).build().perform();
    Thread.sleep(2000);

    timeLine.click();
    Thread.sleep(2000);
    WebElement testtimecode = driver.findElement(By.xpath("//*[contains(text(),'00:0" + xp + ":')]"));

    System.out.println(testtimecode.getText());
    System.out.println(testtimecode1.getText());

    Assert.assertNotEquals(testtimecode.getText(), starttime);
    //Assert.assertNotEquals("111", "1");

}

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

License:Apache License

/**
 * A test.//  w  ww. j a v  a2s.  c o  m
 */
@Test
public void specialSpaceKeys() {
    final WebDriver driver = getWebDriver("/javascriptPage.html");

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

    element.sendKeys("abcd" + Keys.SPACE + "fgh" + Keys.SPACE + "ij");
    assertThat(element.getAttribute("value"), is("abcd fgh ij"));
}

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

License:Apache License

/**
 * {@inheritDoc}/*w w w .ja v a 2 s.  c  o  m*/
 */
@Override
public void click() {
    AppThread.exec(contextItem.statusCode, new Sync<Object>() {
        @Override
        public Object perform() {
            validate(false);
            node.eval(SCROLL_INTO_VIEW);
            if (contextItem.context.get().keyboard.get().isShiftPressed()) {
                node.eval(new StringBuilder().append("this.origOnclick = this.onclick;")
                        .append("this.onclick=function(event){").append("  this.target='_blank';")
                        .append("  if(event){").append("    if(event.stopPropagation){")
                        .append("      event.stopPropagation();").append("    }").append("  }")
                        .append("  if(this.origOnclick){").append("    this.origOnclick(event? event: null);")
                        .append("  }").append("  this.onclick = this.origOnclick;").append("};").toString());
            }
            return null;
        }
    });

    if (node instanceof HTMLOptionElement) {
        AppThread.exec(contextItem.statusCode, new Sync<Object>() {
            @Override
            public Object perform() {
                validate(false);
                try {
                    new ElementServer((JSObject) ((HTMLOptionElement) node).getParentNode(), contextItem)
                            .click();
                } catch (RemoteException e) {
                    Util.handleException(e);
                }
                int index = ((HTMLOptionElement) node).getIndex();
                for (int i = 0; i <= index; i++) {
                    contextItem.context.get().robot.get().keysType(Keys.DOWN);
                }
                contextItem.context.get().robot.get().keysType(Keys.SPACE);
                return null;
            }
        });
    } else {
        AppThread.exec(contextItem.statusCode, new Sync<Object>() {
            @Override
            public Object perform() {
                validate(true);
                final JSObject obj = (JSObject) node.call("getBoundingClientRect");
                final double top = Double.parseDouble(obj.getMember("top").toString());
                final double left = Double.parseDouble(obj.getMember("left").toString());
                final double bottom = Double.parseDouble(obj.getMember("bottom").toString());
                final double right = Double.parseDouble(obj.getMember("right").toString());
                double clickX = (left + right) / 2d;
                double clickY = (top + bottom) / 2d;
                ElementServer doc = ElementServer.create(contextItem);
                if (!node.equals(doc.node.eval(
                        "(function(){return document.elementFromPoint(" + clickX + "," + clickY + ");})();"))) {
                    final Stage stage = contextItem.stage.get();
                    final int minX = Math.max(0, (int) Math.floor(left));
                    final int maxX = Math.min((int) Math.ceil(stage.getScene().getWidth()),
                            (int) Math.ceil(right));
                    final int minY = Math.max(0, (int) Math.floor(top));
                    final int maxY = Math.min((int) Math.ceil(stage.getScene().getHeight()),
                            (int) Math.ceil(bottom));
                    final int incX = (int) Math.max(1, .05d * (double) (maxX - minX));
                    final int incY = (int) Math.max(1, .05d * (double) (maxY - minY));
                    for (int x = minX; x <= maxX; x += incX) {
                        boolean found = false;
                        for (int y = minY; y <= maxY; y += incY) {
                            if (node.equals(doc.node.eval("(function(){return document.elementFromPoint(" + x
                                    + "," + y + ");})();"))) {
                                clickX = x;
                                clickY = y;
                                found = true;
                                break;
                            }
                        }
                        if (found) {
                            break;
                        }
                    }
                }
                final org.openqa.selenium.Point frameLocation = contextItem.selectedFrameLocation();
                contextItem.context.get().robot.get().mouseMove(clickX + frameLocation.getX(),
                        clickY + frameLocation.getY());
                contextItem.context.get().robot.get().mouseClick(MouseButton.LEFT);
                return null;
            }
        });
    }
}

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

License:Apache License

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

    value = value.replace("${KEY_ALT}", Keys.ALT);
    value = value.replace("${KEY_CONTROL}", Keys.CONTROL);
    value = value.replace("${KEY_CTRL}", Keys.CONTROL);
    value = value.replace("${KEY_META}", Keys.META);
    value = value.replace("${KEY_COMMAND}", Keys.COMMAND);
    value = value.replace("${KEY_SHIFT}", Keys.SHIFT);

    value = value.replace("${KEY_BACKSPACE}", Keys.BACK_SPACE);
    value = value.replace("${KEY_BKSP}", Keys.BACK_SPACE);
    value = value.replace("${KEY_DELETE}", Keys.DELETE);
    value = value.replace("${KEY_DEL}", Keys.DELETE);
    value = value.replace("${KEY_ENTER}", Keys.ENTER);
    value = value.replace("${KEY_EQUALS}", Keys.EQUALS);
    value = value.replace("${KEY_ESCAPE}", Keys.ESCAPE);
    value = value.replace("${KEY_ESC}", Keys.ESCAPE);
    value = value.replace("${KEY_INSERT}", Keys.INSERT);
    value = value.replace("${KEY_INS}", Keys.INSERT);
    value = value.replace("${KEY_PAUSE}", Keys.PAUSE);
    value = value.replace("${KEY_SEMICOLON}", Keys.SEMICOLON);
    value = value.replace("${KEY_SPACE}", Keys.SPACE);
    value = value.replace("${KEY_TAB}", Keys.TAB);

    value = value.replace("${KEY_LEFT}", Keys.LEFT);
    value = value.replace("${KEY_UP}", Keys.UP);
    value = value.replace("${KEY_RIGHT}", Keys.RIGHT);
    value = value.replace("${KEY_DOWN}", Keys.DOWN);
    value = value.replace("${KEY_PAGE_UP}", Keys.PAGE_UP);
    value = value.replace("${KEY_PGUP}", Keys.PAGE_UP);
    value = value.replace("${KEY_PAGE_DOWN}", Keys.PAGE_DOWN);
    value = value.replace("${KEY_PGDN}", Keys.PAGE_DOWN);
    value = value.replace("${KEY_END}", Keys.END);
    value = value.replace("${KEY_HOME}", Keys.HOME);

    value = value.replace("${KEY_NUMPAD0}", Keys.NUMPAD0);
    value = value.replace("${KEY_N0}", Keys.NUMPAD0);
    value = value.replace("${KEY_NUMPAD1}", Keys.NUMPAD1);
    value = value.replace("${KEY_N1}", Keys.NUMPAD1);
    value = value.replace("${KEY_NUMPAD2}", Keys.NUMPAD2);
    value = value.replace("${KEY_N2}", Keys.NUMPAD2);
    value = value.replace("${KEY_NUMPAD3}", Keys.NUMPAD3);
    value = value.replace("${KEY_N3}", Keys.NUMPAD3);
    value = value.replace("${KEY_NUMPAD4}", Keys.NUMPAD4);
    value = value.replace("${KEY_N4}", Keys.NUMPAD4);
    value = value.replace("${KEY_NUMPAD5}", Keys.NUMPAD5);
    value = value.replace("${KEY_N5}", Keys.NUMPAD5);
    value = value.replace("${KEY_NUMPAD6}", Keys.NUMPAD6);
    value = value.replace("${KEY_N6}", Keys.NUMPAD6);
    value = value.replace("${KEY_NUMPAD7}", Keys.NUMPAD7);
    value = value.replace("${KEY_N7}", Keys.NUMPAD7);
    value = value.replace("${KEY_NUMPAD8}", Keys.NUMPAD8);
    value = value.replace("${KEY_N8}", Keys.NUMPAD8);
    value = value.replace("${KEY_NUMPAD9}", Keys.NUMPAD9);
    value = value.replace("${KEY_N9}", Keys.NUMPAD9);
    value = value.replace("${KEY_ADD}", Keys.ADD);
    value = value.replace("${KEY_NUM_PLUS}", Keys.ADD);
    value = value.replace("${KEY_DECIMAL}", Keys.DECIMAL);
    value = value.replace("${KEY_NUM_PERIOD}", Keys.DECIMAL);
    value = value.replace("${KEY_DIVIDE}", Keys.DIVIDE);
    value = value.replace("${KEY_NUM_DIVISION}", Keys.DIVIDE);
    value = value.replace("${KEY_MULTIPLY}", Keys.MULTIPLY);
    value = value.replace("${KEY_NUM_MULTIPLY}", Keys.MULTIPLY);
    value = value.replace("${KEY_SEPARATOR}", Keys.SEPARATOR);
    value = value.replace("${KEY_SEP}", Keys.SEPARATOR);
    value = value.replace("${KEY_SUBTRACT}", Keys.SUBTRACT);
    value = value.replace("${KEY_NUM_MINUS}", Keys.SUBTRACT);

    value = value.replace("${KEY_F1}", Keys.F1);
    value = value.replace("${KEY_F2}", Keys.F2);
    value = value.replace("${KEY_F3}", Keys.F3);
    value = value.replace("${KEY_F4}", Keys.F4);
    value = value.replace("${KEY_F5}", Keys.F5);
    value = value.replace("${KEY_F6}", Keys.F6);
    value = value.replace("${KEY_F7}", Keys.F7);
    value = value.replace("${KEY_F8}", Keys.F8);
    value = value.replace("${KEY_F9}", Keys.F9);
    value = value.replace("${KEY_F10}", Keys.F10);
    value = value.replace("${KEY_F11}", Keys.F11);
    value = value.replace("${KEY_F12}", Keys.F12);

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

    return null;/*from ww w  . j  av  a2 s.  c  om*/
}

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

License:Apache License

@Test
public void testDeselectAllowedKeyboardInput() {
    openTestURL();/*w ww.j a v a  2  s  .co m*/

    setSelectionModelSingle(true);

    getGridElement().getHeaderCell(0, 0).click();

    new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();

    new Actions(getDriver()).sendKeys(Keys.SPACE).perform();

    assertTrue("Row 0 should be selected after pressing space", isRowSelected(0));

    new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();

    new Actions(getDriver()).sendKeys(Keys.SPACE).perform();

    assertFalse("Row 0 should be deselected after pressing space another row", isRowSelected(0));
    assertTrue("Row 1 should be selected after pressing space", isRowSelected(1));

    new Actions(getDriver()).sendKeys(Keys.SPACE).perform();

    assertFalse("Row should be deselected after pressing space again", isRowSelected(1));
}

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

License:Apache License

@Test
public void testDeselectNotAllowedKeyboardInput() {
    openTestURL();/*from w  ww.  java  2  s  . c  o m*/

    setSelectionModelSingle(false);

    getGridElement().getHeaderCell(0, 0).click();
    new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();

    new Actions(getDriver()).sendKeys(Keys.SPACE).perform();

    assertTrue("Row 0 should be selected after pressing space", isRowSelected(0));

    new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();

    new Actions(getDriver()).sendKeys(Keys.SPACE).perform();

    assertFalse("Row 0 should be deselected after pressing space another row", isRowSelected(0));
    assertTrue("Row 1 should be selected after pressing space", isRowSelected(1));

    new Actions(getDriver()).sendKeys(Keys.SPACE).perform();

    assertTrue("Row should remain selected after pressing space again", isRowSelected(1));
}

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

License:Apache License

@Test
public void testKeyboardSelection() {
    openTestURL();/*from  w  w  w . j  a  v  a  2 s. c  o m*/
    setSelectionModelMulti();

    GridElement grid = getGridElement();
    grid.getCell(3, 1).click();
    new Actions(getDriver()).sendKeys(Keys.SPACE).perform();

    assertTrue("Grid row 3 was not selected with space key.", grid.getRow(3).isSelected());

    new Actions(getDriver()).sendKeys(Keys.SPACE).perform();

    assertTrue("Grid row 3 was not deselected with space key.", !grid.getRow(3).isSelected());

    grid.scrollToRow(500);

    new Actions(getDriver()).sendKeys(Keys.SPACE).perform();

    assertTrue("Grid row 3 was not selected with space key.", grid.getRow(3).isSelected());
}

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

License:Apache License

@Test
public void testKeyboardWithSingleSelection() {
    openTestURL();/*w ww .  j a  v a  2 s .  c o m*/
    setSelectionModelSingle();

    GridElement grid = getGridElement();
    grid.getCell(3, 1).click();

    assertTrue("Grid row 3 was not selected with clicking.", grid.getRow(3).isSelected());

    new Actions(getDriver()).sendKeys(Keys.SPACE).perform();

    assertTrue("Grid row 3 was not deselected with space key.", !grid.getRow(3).isSelected());

    new Actions(getDriver()).sendKeys(Keys.SPACE).perform();

    assertTrue("Grid row 3 was not selected with space key.", grid.getRow(3).isSelected());

    grid.scrollToRow(500);

    new Actions(getDriver()).sendKeys(Keys.SPACE).perform();

    assertTrue("Grid row 3 was not deselected with space key.", !grid.getRow(3).isSelected());
}

From source file:com.vaadin.tests.components.orderedlayout.OrderedLayoutExpandTest.java

License:Apache License

private void openDebugExamineComponentHierarchyTab() {
    WebElement button = findElement(By.xpath("//button[@title='Examine component hierarchy']"));
    // can't use 'click()' with zoom levels other than 100%
    button.sendKeys(Keys.chord(Keys.SPACE));
}

From source file:com.vaadin.tests.components.orderedlayout.OrderedLayoutExpandTest.java

License:Apache License

private void clickDebugCheckLayoutsForPotentialProblems() {
    WebElement button = findElement(By.xpath("//button[@title='Check layouts for potential problems']"));

    button.sendKeys(Keys.chord(Keys.SPACE));
}