Example usage for org.openqa.selenium Keys ENTER

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

Introduction

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

Prototype

Keys ENTER

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

Click Source Link

Usage

From source file:org.rstudio.studio.selenium.WorkbenchTests.java

License:Open Source License

@Test
public void testWorkbenchPersistance() throws Exception {
    clearWorkspace();//from w  w w. j  av  a  2s.  c  om

    // Add a variable to the workspace
    (new Actions(driver_)).sendKeys(Keys.ESCAPE + "selenium <- function() { 42 }" + Keys.ENTER).perform();

    // Save the workspace 
    WebElement saveItem = MenuNavigator.getMenuItem(driver_, "Session", "Save Workspace As...");
    saveItem.click();

    WebElement saveDialog = DialogTestUtils.waitForModalToAppear(driver_);
    DialogTestUtils.waitForFocusedInput(driver_, saveDialog);

    File tempFile = File.createTempFile("rstudio-selenium-workspace-", ".RData");
    String workspaceFilePath = tempFile.getAbsolutePath();
    tempFile.delete();

    (new Actions(driver_)).sendKeys(workspaceFilePath + Keys.ENTER).perform();

    DialogTestUtils.waitForModalToDisappear(driver_);

    // Clear the workspace and load it again
    clearWorkspace();

    WebElement loadItem = MenuNavigator.getMenuItem(driver_, "Session", "Load Workspace...");
    loadItem.click();

    WebElement loadDialog = DialogTestUtils.waitForModalToAppear(driver_);
    DialogTestUtils.waitForFocusedInput(driver_, loadDialog);

    (new Actions(driver_)).sendKeys(workspaceFilePath + Keys.ENTER).perform();

    DialogTestUtils.waitForModalToDisappear(driver_);

    // List the workspace and see if the variable is present
    ConsoleTestUtils.beginConsoleInteraction(driver_);
    (new Actions(driver_)).sendKeys(Keys.chord(Keys.CONTROL + "l")).sendKeys(Keys.ESCAPE + "ls()" + Keys.ENTER)
            .perform();

    ConsoleTestUtils.waitForConsoleContainsText(driver_, "selenium");
}

From source file:org.rstudio.studio.selenium.WorkbenchTests.java

License:Open Source License

private void clearWorkspace() {
    // Clear out the workspace and make sure it's clear
    WebElement menuItem = MenuNavigator.getMenuItem(driver_, "Session", "Clear Workspace...");
    menuItem.click();/*from   www  .j a va2s .c o  m*/
    DialogTestUtils.respondToModalDialog(driver_, "Yes");

    ConsoleTestUtils.beginConsoleInteraction(driver_);
    (new Actions(driver_)).sendKeys(Keys.ESCAPE + "ls()" + Keys.ENTER).perform();

    ConsoleTestUtils.waitForConsoleContainsText(driver_, "character(0)");
}

From source file:org.safs.selenium.webdriver.lib.WDLibrary.java

License:Open Source License

/**
 * Convert a Java KEYCODE to a Selenium WebDriver Keys Enum
 * @param keycode int, a java keycode/*from  ww w .j  a v  a2s .  c o m*/
 * @return Keys enum for (primarily) non-printable (control) characters, or null.
 */
public static Keys convertToKeys(int keycode) {
    Keys key = null;
    switch (keycode) {
    case java.awt.event.KeyEvent.VK_ADD:
        key = Keys.ADD;
        break;
    case java.awt.event.KeyEvent.VK_ALT:
        key = Keys.ALT;
        break;
    case java.awt.event.KeyEvent.VK_KP_DOWN:
        key = Keys.ARROW_DOWN;
        break;
    case java.awt.event.KeyEvent.VK_KP_LEFT:
        key = Keys.ARROW_LEFT;
        break;
    case java.awt.event.KeyEvent.VK_KP_RIGHT:
        key = Keys.ARROW_RIGHT;
        break;
    case java.awt.event.KeyEvent.VK_KP_UP:
        key = Keys.ARROW_UP;
        break;
    case java.awt.event.KeyEvent.VK_BACK_SPACE:
        key = Keys.BACK_SPACE;
        break;
    case java.awt.event.KeyEvent.VK_CANCEL:
        key = Keys.CANCEL;
        break;
    case java.awt.event.KeyEvent.VK_CLEAR:
        key = Keys.CLEAR;
        break;
    case java.awt.event.KeyEvent.VK_WINDOWS:
        key = Keys.COMMAND;
        break;
    case java.awt.event.KeyEvent.VK_CONTROL:
        key = Keys.CONTROL;
        break;
    case java.awt.event.KeyEvent.VK_DECIMAL:
        key = Keys.DECIMAL;
        break;
    case java.awt.event.KeyEvent.VK_DELETE:
        key = Keys.DELETE;
        break;
    case java.awt.event.KeyEvent.VK_DIVIDE:
        key = Keys.DIVIDE;
        break;
    case java.awt.event.KeyEvent.VK_DOWN:
        key = Keys.DOWN;
        break;
    case java.awt.event.KeyEvent.VK_END:
        key = Keys.END;
        break;
    case java.awt.event.KeyEvent.VK_ENTER:
        key = Keys.ENTER;
        break;
    case java.awt.event.KeyEvent.VK_EQUALS:
        key = Keys.EQUALS;
        break;
    case java.awt.event.KeyEvent.VK_ESCAPE:
        key = Keys.ESCAPE;
        break;
    case java.awt.event.KeyEvent.VK_F1:
        key = Keys.F1;
        break;
    case java.awt.event.KeyEvent.VK_F2:
        key = Keys.F2;
        break;
    case java.awt.event.KeyEvent.VK_F3:
        key = Keys.F3;
        break;
    case java.awt.event.KeyEvent.VK_F4:
        key = Keys.F4;
        break;
    case java.awt.event.KeyEvent.VK_F5:
        key = Keys.F5;
        break;
    case java.awt.event.KeyEvent.VK_F6:
        key = Keys.F6;
        break;
    case java.awt.event.KeyEvent.VK_F7:
        key = Keys.F7;
        break;
    case java.awt.event.KeyEvent.VK_F8:
        key = Keys.F8;
        break;
    case java.awt.event.KeyEvent.VK_F9:
        key = Keys.F9;
        break;
    case java.awt.event.KeyEvent.VK_F10:
        key = Keys.F10;
        break;
    case java.awt.event.KeyEvent.VK_F11:
        key = Keys.F11;
        break;
    case java.awt.event.KeyEvent.VK_F12:
        key = Keys.F12;
        break;
    case java.awt.event.KeyEvent.VK_HELP:
        key = Keys.HELP;
        break;
    case java.awt.event.KeyEvent.VK_HOME:
        key = Keys.HOME;
        break;
    case java.awt.event.KeyEvent.VK_INSERT:
        key = Keys.INSERT;
        break;
    case java.awt.event.KeyEvent.VK_LEFT:
        key = Keys.LEFT;
        break;
    case java.awt.event.KeyEvent.VK_META:
        key = Keys.META;
        break;
    case java.awt.event.KeyEvent.VK_MULTIPLY:
        key = Keys.MULTIPLY;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD0:
        key = Keys.NUMPAD0;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD1:
        key = Keys.NUMPAD1;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD2:
        key = Keys.NUMPAD2;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD3:
        key = Keys.NUMPAD3;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD4:
        key = Keys.NUMPAD4;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD5:
        key = Keys.NUMPAD5;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD6:
        key = Keys.NUMPAD6;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD7:
        key = Keys.NUMPAD7;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD8:
        key = Keys.NUMPAD8;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD9:
        key = Keys.NUMPAD9;
        break;
    case java.awt.event.KeyEvent.VK_PAGE_DOWN:
        key = Keys.PAGE_DOWN;
        break;
    case java.awt.event.KeyEvent.VK_PAGE_UP:
        key = Keys.PAGE_UP;
        break;
    case java.awt.event.KeyEvent.VK_PAUSE:
        key = Keys.PAUSE;
        break;
    case java.awt.event.KeyEvent.VK_RIGHT:
        key = Keys.RIGHT;
        break;
    case java.awt.event.KeyEvent.VK_SEMICOLON:
        key = Keys.SEMICOLON;
        break;
    case java.awt.event.KeyEvent.VK_SEPARATOR:
        key = Keys.SEPARATOR;
        break;
    case java.awt.event.KeyEvent.VK_SHIFT:
        key = Keys.SHIFT;
        break;
    case java.awt.event.KeyEvent.VK_SPACE:
        key = Keys.SPACE;
        break;
    case java.awt.event.KeyEvent.VK_SUBTRACT:
        key = Keys.SUBTRACT;
        break;
    case java.awt.event.KeyEvent.VK_TAB:
        key = Keys.TAB;
        break;
    case java.awt.event.KeyEvent.VK_UP:
        key = Keys.UP;
        break;
    }
    return key;
}

From source file:org.sonarqube.tests.measure.ProjectDashboardTest.java

License:Open Source License

@Test
public void display_tags_with_edit() {
    executeBuild("shared/xoo-sample", "sample-with-tags", "Sample with tags");
    // Add some tags to another project to have them in the list
    tester.wsClient().wsConnector().call(new PostRequest("api/project_tags/set")
            .setParam("project", "sample-with-tags").setParam("tags", "foo,bar,baz"));

    executeBuild("shared/xoo-sample", "sample", "Sample");
    ProjectDashboardPage page = tester.openBrowser().logIn().submitCredentials(adminUser)
            .openProjectDashboard("sample");
    page.shouldHaveTags("No tags").shouldBeEditable().openTagEditor().getTagAtIdx(2).click();
    page.shouldHaveTags("foo").sendKeysToTagsInput("test").getTagAtIdx(0).should(text("+ test")).click();
    page.shouldHaveTags("foo", "test").getTagAtIdx(1).should(text("test"));
    page.sendKeysToTagsInput(Keys.ENTER).shouldHaveTags("test");
}

From source file:org.testeditor.fixture.web.WebFixtureTest.java

License:Open Source License

/**
 * Test for pressSpecialKeyOnElement./*from   w w  w  . jav  a2 s . c  o m*/
 */
@Test
public void pressSpecialKeyOnElementWorksCorrectWithKnownKeys() {
    startWebApplication(WEB_INDEX_PAGE);

    fixture.insertIntoField("Max Mustermann", "user");
    fixture.insertIntoField("maxi", "password");
    fixture.pressSpecialKeyOnElement(Keys.TAB.name(), "user");
    fixture.pressSpecialKeyOnElement(Keys.TAB.name(), "user");
    fixture.pressSpecialKeyOnElement(Keys.ENTER.name(), "user");

    fixture.checkTextIsPresentOnPage("Eine Beispiel Web-Applikation");

    /* Not possible with HtmlUnitDriver but works with real Driver */
    // startWebApplication(WEB_ELEMENTS_PAGE);
    // assertTrue(fixture.checkIsSelected("checkbox"));
    // assertTrue(fixture.pressSpecialKeyOnElement(Keys.SPACE.name(),
    // "checkbox"));
    // assertFalse(fixture.checkIsSelected("checkbox"));
}

From source file:org.tomitribe.tribestream.registryng.functionaltests.pages.EndpointDetailsPage.java

License:Apache License

public void enterVerb(final String newVerb) throws Exception {
    WebElement textField = verbSingleSelect.findElement(By.cssSelector("input[type='text']"));
    verbSingleSelect.click();/*from   w  w  w .  ja  v  a2 s .  c o  m*/
    Thread.sleep(5000);
    guardNoRequest(textField).sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.BACK_SPACE, newVerb, Keys.ENTER);
}

From source file:org.uiautomation.ios.selenium.FormHandlingTest.java

License:Apache License

@Test(enabled = false)
public void testShouldSubmitAFormUsingTheEnterKey() {
    driver.get(pages.formPage);/* w  ww . ja  va  2s . co m*/
    WebElement nestedForm = driver.findElement(By.id("nested_form"));
    WebElement input = nestedForm.findElement(By.name("x"));
    input.sendKeys(Keys.ENTER);
    waitFor(pageTitleToBe(driver, "We Arrive Here"));
    assertTrue(driver.getCurrentUrl().endsWith("?x=name"));
}

From source file:org.uiautomation.ios.selenium.FormHandlingTest.java

License:Apache License

@Test
public void testCanUseEnterKeyToSubmitForm() {
    driver.get(pages.formPage);/*from   ww w . j av a2s . c o  m*/
    WebElement element = driver.findElement(By.cssSelector("#nested_form input[type='text']"));
    final String curURL = driver.getCurrentUrl();
    element.sendKeys("something" + Keys.ENTER);
    new WebDriverWait(driver, 3).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver webDriver) {
            return !webDriver.getCurrentUrl().equals(curURL);
        }
    });
    assertTrue(driver.getCurrentUrl().endsWith("something"));
}

From source file:org.vaadin.testbenchsauce.BaseTestBenchTestCase.java

protected String selectComboBoxOptionByIndex(int optionIndex) {
    logStep.info("Selecting combobox(0) option index: " + optionIndex);

    WebElement comboBox = findElement(By.xpath("//div[contains(@class, 'v-filterselect')]"));
    WebElement filterSelectButton = comboBox.findElement(By.className("v-filterselect-button"));//show how to find this in the chrome dev tools
    filterSelectButton.click();/*from  ww  w.  ja va 2  s.c  om*/
    WebElement filterInput = comboBox.findElement(By.className("v-filterselect-input"));
    filterInput.sendKeys(Keys.ARROW_DOWN); //one to enter list selection
    for (int i = 0; i < optionIndex; i++) {
        filterInput.sendKeys(Keys.ARROW_DOWN);
    }
    filterInput.sendKeys(Keys.ENTER);
    return getElementValue(filterInput);
}

From source file:org.wso2.carbon.greg.store.SearchResultsPage.java

License:Open Source License

/**
 * Constructor for search results page. This performs search of any given query on store and constructs
 * the results page. This verifies if the driver is in results page before returns.
 *
 * @param driver   WebDriver object to perform operations.
 * @param query    The search query.// w w w.j a v a 2 s  .  c om
 * @param hitEnter True, if the search needs to be done by hitting the enter button on search field.
 */
public SearchResultsPage(WebDriver driver, String query, boolean hitEnter) {

    this.driver = driver;
    uiElementMapper = UIElementMapper.getInstance();
    String searchbarMapperId = "store.searchbar.id";

    this.driver.findElement(By.id(uiElementMapper.getElement(searchbarMapperId))).click();
    this.driver.findElement(By.id(uiElementMapper.getElement(searchbarMapperId))).clear();
    if (hitEnter) {
        this.driver.findElement(By.id(uiElementMapper.getElement(searchbarMapperId))).sendKeys(query,
                Keys.ENTER);
    } else {
        this.driver.findElement(By.id(uiElementMapper.getElement(searchbarMapperId))).sendKeys(query);
        this.driver.findElement(By.id(uiElementMapper.getElement(searchbarMapperId))).click();
    }
    assertTrue(driver.getCurrentUrl().contains("q="));
}