Example usage for org.openqa.selenium WebElement sendKeys

List of usage examples for org.openqa.selenium WebElement sendKeys

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement sendKeys.

Prototype

void sendKeys(CharSequence... keysToSend);

Source Link

Document

Use this method to simulate typing into an element, which may set its value.

Usage

From source file:com.example.selenium.find.elements.FindElementXPath.java

@Test
public void findByPredicates() {

    WebElement element = driver.findElement(By.xpath("//form/div[1]/input"));
    element.sendKeys("I have found you");
}

From source file:com.example.selenium.find.elements.FindlElementCSS.java

@Test
public void findByRelativePath() {

    WebElement element = driver.findElement(By.cssSelector("input"));
    element.sendKeys("Jayasimha");
}

From source file:com.example.selenium.grid.SeleniumGridChrome.java

@Test(dataProvider = "xlsTest")
public void testLogin(String useName, String password) throws InterruptedException {

    driver.get("http://localhost:8080/WebApplication/pages/login.html");
    WebElement userNameText = driver.findElement(By.name("email"));
    userNameText.sendKeys(useName);

    WebElement passwordText = driver.findElement(By.id("password"));
    passwordText.sendKeys(password);/*from w w w.  ja  va2  s .  com*/

    WebElement loginButton = driver.findElement(By.linkText("Login"));
    loginButton.click();
    if (driver.getTitle().equals("SB Admin 2 - Bootstrap Admin Theme")) {
        assertTrue(true);
    } else {
        assertTrue(false);
    }
}

From source file:com.example.selenium.grid.SeleniumGridIE.java

@Test(dataProvider = "xlsTest")
public void testLogin(String useName, String password) throws InterruptedException {

    driver.get("http://localhost:8080/WebApplication/pages/login.html");
    Thread.sleep(2000);//from w w  w.j  av  a2  s  .  c om
    WebElement userNameText = driver.findElement(By.name("email"));
    userNameText.sendKeys(useName);

    WebElement passwordText = driver.findElement(By.id("password"));
    passwordText.sendKeys(password);

    WebElement loginButton = driver.findElement(By.linkText("Login"));
    loginButton.click();
    if (driver.getTitle().equals("SB Admin 2 - Bootstrap Admin Theme")) {
        assertTrue(true);
    } else {
        assertTrue(false);
    }
}

From source file:com.example.selenium.grid.SeleniumGridTest.java

@Test
public void testLogin() throws InterruptedException {

    WebElement userNameText = driver.findElement(By.name("email"));
    userNameText.sendKeys("jayasimha.bj@gmail.com");

    WebElement passwordText = driver.findElement(By.id("password"));
    passwordText.sendKeys("welcome123");

    WebElement loginButton = driver.findElement(By.linkText("Login"));
    loginButton.click();/* www. j a  v  a2s .  com*/
    if (driver.getTitle().equals("SB Admin 2 - Bootstrap Admin Theme")) {
        assertTrue(true);
    } else {
        assertTrue(false);
    }
}

From source file:com.fmb.common.BrowserEmulator.java

License:Apache License

/**
 * Type text at the page element<br>
 * Before typing, try to clear existed text
 * @param xpath//from w  ww. j  a v  a2 s  . co  m
 *            the element's xpath
 * @param text
 *            the input text
 */
public void type(String xpath, String text) {
    pause(stepInterval);
    expectElementExistOrNot(true, xpath, timeout);

    WebElement we = browserCore.findElement(By.xpath(xpath));
    try {
        we.clear();
    } catch (Exception e) {
        logger.warn("Failed to clear text at " + xpath);
    }
    try {
        we.sendKeys(text);
    } catch (Exception e) {
        e.printStackTrace();
        handleFailure("Failed to type " + text + " at " + xpath);
    }

    logger.info("Type " + text + " at " + xpath);
}

From source file:com.formkiq.web.SeleniumTestBase.java

License:Apache License

/**
 *
 * @param email {@link String}/*from   www  .  j  a  v  a 2s  . co  m*/
 */
@Override
public String login(final String email) {

    String loginURL = getDefaultHostAndPort() + "/login";
    getDriver().get(loginURL);

    if (driver.getCurrentUrl().endsWith("/login")) {

        WebElement element = findElementBy(By.name("username"));
        element.sendKeys(email);

        element = findElementBy(By.name("password"));
        element.sendKeys(getDefaultPass());

        element.submit();
    }

    return null;
}

From source file:com.formkiq.web.WorkflowAddControllerIntegrationTest.java

License:Apache License

/**
 * testWorkflow01()./*from w ww .ja  v a 2s.c o m*/
 * get workflow as ADMIN
 * @throws Exception Exception
 */
@Test
public void testCreateWorkflow01() throws Exception {
    // given
    final long sleep = 250L;
    FormJSON form = TestDataBuilder.createStoreReceipt();
    Workflow workflow = TestDataBuilder.createWorkflow(form);

    String token = login();
    String folder = createFolder(token, getDefaultEmail());

    addFileToFolder(token, folder, workflow, form);

    // when
    login(getDefaultEmail());
    getDriver().navigate().to(getDefaultHostAndPort() + "/user/dashboard");
    waitForJSandJQueryToLoad();

    assertEquals("FormKiQ Server - Dashboard", getTitle());

    findElementBy(By.className("add_0")).click();

    // then (verify on correct page)
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e1", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Store Receipt", getTitle());

    // when (enter data)
    WebElement element = findElementBy(By.name("1"));
    element.sendKeys("10");

    element = findElementBy(By.name("1"));
    assertEquals("10", element.getAttribute("value"));

    JavascriptExecutor jsExecutor = (JavascriptExecutor) getDriver();
    jsExecutor.executeScript("calculate();", element);

    Thread.sleep(sleep);

    getDriver().navigate().refresh();

    // then (verify data calculations)
    element = findElementBy(By.name("2"));
    assertEquals("$0.70", element.getAttribute("value"));

    element = findElementBy(By.name("3"));
    assertEquals("$7.99", element.getAttribute("value"));

    element = findElementBy(By.name("4"));
    assertEquals("$18.69", element.getAttribute("value"));

    List<WebElement> elements = getSubmitButtons();
    assertEquals(1, elements.size());

    // when (submit)
    submitByName("_eventId_next", "Next");

    // then verify complete
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e2", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Sample WF Complete", getTitle());

    assertTrue(getDriver().getPageSource().contains("end-of-document"));

    String pageSource = getDriver().getPageSource();
    assertTrue(pageSource.contains("The workflow has been saved."));

    FolderFormsListDTO formlist = getFolderFileList(token, folder, workflow.getUUID());

    assertEquals(1, formlist.getForms().size());
    FormDTO fdto = formlist.getForms().get(0);
    assertNotEquals(workflow.getUUID(), fdto.getUUID());

    byte[] data = getFolderFile(token, folder, fdto.getUUID(), MediaType.valueOf(ACCEPT_HEADER_V1 + "+zip"),
            false).getBody();
    ArchiveDTO archive = this.archiveService.extractJSONFromZipFile(data);
    workflow = archive.getWorkflow();

    assertNotNull(workflow);
    assertEquals(1, archive.getForms().size());
    form = archive.getForms().values().iterator().next();

    assertTrue(workflow.getSteps().contains(form.getUUID()));
    assertEquals(workflow.getParentUUID(), form.getParentUUID());

    int i = 1;
    assertEquals("$10.00", findField(form, i++).get().getValue());
    assertEquals("$0.70", findField(form, i++).get().getValue());
    assertEquals("$7.99", findField(form, i++).get().getValue());
    assertEquals("$18.69", findField(form, i++).get().getValue());
}

From source file:com.formkiq.web.WorkflowAddControllerIntegrationTest.java

License:Apache License

/**
 * testWorkflow03().//ww w  . ja v a 2s . c  o  m
 * Fill Form, Press Next then change URL to previous form
 * @throws Exception Exception
 */
@Test
public void testCreateWorkflow03() throws Exception {
    // given
    FormJSON form0 = TestDataBuilder.createStoreReceipt();
    FormJSON form1 = TestDataBuilder.createSimpleForm();
    Workflow workflow = TestDataBuilder.createWorkflow(form0, form1);

    String token = login();
    String folder = createFolder(token, getDefaultEmail());

    addFileToFolder(token, folder, workflow, form0, form1);

    // when
    login(getDefaultEmail());
    getDriver().navigate().to(getDefaultHostAndPort() + "/user/dashboard");
    waitForJSandJQueryToLoad();

    assertEquals("FormKiQ Server - Dashboard", getTitle());

    findElementBy(By.className("add_0")).click();

    // then (verify on correct page)
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e1", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Store Receipt", getTitle());

    // when (enter data)
    WebElement element = findElementBy(By.name("1"));
    element.sendKeys("10");
    findElementBy(By.id("nextbutton")).click();

    // then verify summary
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e2", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Simple Form", getTitle());

    // when move to previous page
    findElementBy(By.id("previousbutton")).click();

    // then verify summary
    assertEquals(getDefaultHostAndPort() + "/flow/workflow?execution=s1e1", getDriver().getCurrentUrl());
    assertEquals("FormKiQ Server - Store Receipt", getTitle());
}

From source file:com.formkiq.web.WorkflowEditorControllerIntegrationTest.java

License:Apache License

/**
 * Edits Field./* w  ww.ja v  a  2s. com*/
 *
 * @param fieldid {@link String}
 * @param values {@link Map}
 * @throws InterruptedException InterruptedException
 */
private void editField(final String fieldid, final Map<String, String> values) throws InterruptedException {

    clickEditFieldButton(fieldid);

    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("fieldeditorform")));

    for (Map.Entry<String, String> e : values.entrySet()) {
        String field = e.getKey();
        String value = e.getValue();

        By by = By.xpath("//*[self::textarea|self::input|self::select|self::button]" + "[@data-fieldid='"
                + field + "']");

        WebElement element = findElementBy(by);

        assertTrue(element.isDisplayed());
        String tagname = element.getTagName();

        switch (tagname) {
        case "select":
            Select select = new Select(element);
            waitUntilSelectOptionsPopulated(select);
            select.selectByVisibleText(extractLabelAndValue(value).getLeft());
            break;

        case "button":
            element.click();
            break;
        default:
            element.clear();
            element.sendKeys(value);
            break;
        }
    }

    //findElementBy(By.className("form-modal-update-button")).click();
    click(By.name("_eventId_next"));

    getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("fieldeditorform")));
}