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.formkiq.web.WorkflowEditorControllerIntegrationTest.java

License:Apache License

/**
 * testAddWorkflow14().//from  w w w  .j  a  v a2 s.co  m
 * add textbox and then edit with custom formatter..
 *
 * @throws Exception Exception
 */
@Test
public void testAddWorkflow14() throws Exception {
    // given
    FormJSONFieldType typeSelect = FormJSONFieldType.TEXTBOX;
    Map<String, String> values = new LinkedHashMap<>();
    values.put("20", "Sample Label");
    values.put("40", "Immediate[immediate]");
    values.put("44", "Numbers[DecimalPad]");
    values.put("25", "Custom");
    values.put("61", "tvariable");
    values.put("24", "(ddd)");

    // when - add step
    clickAddNewWorkflow();
    addBlankForm();

    menuDragAndDrop("menu-textbox");
    editField("1", values);

    // then
    WebElement element = findElementBy("input", "data-fieldid", "1");
    assertTrue(element.isDisplayed());

    element.sendKeys("a456");
    assertEquals("(456)", element.getAttribute("value"));

    checkEditField("1", typeSelect, values);
}

From source file:com.fullteaching.backend.e2e.FullTeachingTestE2E.java

License:Apache License

private void login(BrowserUser user, String userEmail, String userPass) {
    user.getDriver().findElement(By.id("download-button")).click();

    // Find form elements (login modal is already opened)
    WebElement userNameField = user.getDriver().findElement(By.id("email"));
    WebElement userPassField = user.getDriver().findElement(By.id("password"));

    // Fill input fields
    userNameField.sendKeys(userEmail);
    userPassField.sendKeys(userPass);/*ww w .  j  a v  a 2  s . co  m*/

    // Ensure fields contain what has been entered
    Assert.assertEquals(userNameField.getAttribute("value"), userEmail);
    Assert.assertEquals(userPassField.getAttribute("value"), userPass);

    user.getDriver().findElement(By.id("log-in-btn")).click();
}

From source file:com.fullteaching.backend.e2e.FullTeachingTestE2ESleep.java

License:Apache License

private void login(BrowserUser user, String userEmail, String userPass) {
    user.getDriver().findElement(By.id("download-button")).click();

    // Find form elements (login modal is already opened)
    WebElement userNameField = user.getDriver().findElement(By.id("email"));
    WebElement userPassField = user.getDriver().findElement(By.id("password"));

    // Fill input fields
    userNameField.sendKeys(userEmail);

    try {//from  ww w  . ja va 2 s.c o  m
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    userPassField.sendKeys(userPass);

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    // Ensure fields contain what has been entered
    Assert.assertEquals(userNameField.getAttribute("value"), userEmail);
    Assert.assertEquals(userPassField.getAttribute("value"), userPass);

    user.getDriver().findElement(By.id("log-in-btn")).click();
}

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

License:Apache License

/**
 * @throws Exception if the test fails/*ww  w .  j a  v a  2  s  .  com*/
 */
@Test
@NotYetImplemented
//TODO: fails because of HTMLElement.getContentEditable doesn't detect DomElement.ATTRIBUTE_VALUE_EMPTY
// this could be a general attribute issue
public void contentEditable() throws Exception {
    final String html = "<html>\n" + "<body contentEditable><p>initial</p></body>\n" + "</html>";

    final WebDriver driver = loadPage2(html);
    final WebElement body = driver.findElement(By.xpath("//body"));
    body.clear();
    body.sendKeys("something");
    assertEquals("something", body.getText());
}

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

License:Apache License

/**
 * @throws Exception if an error occurs//from   www  .  j a va 2 s  . co  m
 */
@Test
@Alerts(DEFAULT = "down: 16,0 down: 49,0 press: 33,33 up: 49,0 up: 16,0"
        + " down: 16,0 down: 220,0 press: 124,124 up: 220,0 up: 16,0", FF = "down: 16,0 down: 49,0 press: 0,33 up: 49,0 up: 16,0"
                + " down: 16,0 down: 220,0 press: 0,124 up: 220,0 up: 16,0")
//https://github.com/SeleniumHQ/selenium/issues/639
@BuggyWebDriver(Browser.FF)
public void shiftKeys() throws Exception {
    final String html = "<html><head><script>\n" + "  function appendMessage(message) {\n"
            + "    document.getElementById('result').innerHTML += message + ' ';\n" + "  }\n"
            + "</script></head>\n" + "<body >\n"
            + "  <input id='input1' onkeyup=\"appendMessage('up: ' + event.keyCode + ',' + event.charCode)\" "
            + "onkeypress=\"appendMessage('press: ' + event.keyCode + ',' + event.charCode)\" "
            + "onkeydown=\"appendMessage('down: ' + event.keyCode + ',' + event.charCode)\"><br>\n"
            + "<p id='result'></p>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);
    final WebElement input = driver.findElement(By.id("input1"));
    final WebElement result = driver.findElement(By.id("result"));
    input.sendKeys("!|");
    assertEquals(getExpectedAlerts()[0], result.getText());
}

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

License:Apache License

/**
 * @throws Exception if the test fails//  w  ww. j  a v a  2s.co  m
 */
@Test
public void typing() throws Exception {
    final String htmlContent = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n"
            + "  <input type='email' id='foo'>\n" + "</form></body></html>";

    final WebDriver driver = loadPage2(htmlContent);

    final WebElement input = driver.findElement(By.id("foo"));
    input.sendKeys("hello");
    assertEquals("hello", input.getAttribute("value"));
}

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

License:Apache License

/**
 * @throws Exception if an error occurs/* w  w w.j  av  a 2 s  . c o  m*/
 */
@Test
@Alerts(DEFAULT = "C:\\fakepath\\pom.xml", FF = "pom.xml", IE = "PATH")
public void getAttribute() throws Exception {
    final String html = "<html><body>\n" + "  <input type='file' id='f'>\n" + "</body></html>";

    final String absolutePath = new File("pom.xml").getAbsolutePath();

    final WebDriver driver = loadPage2(html);
    final WebElement e = driver.findElement(By.id("f"));
    e.sendKeys(absolutePath);
    final String[] expectedAlerts = getExpectedAlerts();
    expectedAlerts[0] = expectedAlerts[0].replace("PATH", absolutePath);
    assertEquals(expectedAlerts[0], e.getAttribute("value"));
}

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

License:Apache License

/**
 * @throws Exception if the test fails//from   ww w .j  a  v  a  2s  .  c  om
 */
@Test
public void type() throws Exception {
    final String html = "<html><head></head><body><input type='number' id='t'/></body></html>";
    final WebDriver driver = loadPage2(html);
    final WebElement t = driver.findElement(By.id("t"));
    t.sendKeys("123");
    assertEquals("123", t.getAttribute("value"));
    t.sendKeys("\b");
    assertEquals("12", t.getAttribute("value"));
    t.sendKeys("\b");
    assertEquals("1", t.getAttribute("value"));
    t.sendKeys("\b");
    assertEquals("", t.getAttribute("value"));
    t.sendKeys("\b");
    assertEquals("", t.getAttribute("value"));
}

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

License:Apache License

/**
 * @throws Exception if the test fails//from   w  ww. j a  va2 s . c  o  m
 */
@Test
public void typeWhileDisabled() throws Exception {
    final String html = "<html><body><input type='number' id='p' disabled='disabled'/></body></html>";
    final WebDriver driver = loadPage2(html);
    final WebElement p = driver.findElement(By.id("p"));
    try {
        p.sendKeys("abc");
        fail();
    } catch (final InvalidElementStateException e) {
        // as expected
    }
    assertEquals("", p.getAttribute("value"));
}

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

License:Apache License

/**
 * @throws Exception if the test fails//from w w w .  ja  v  a2s. co  m
 */
@Test
@Alerts({ "null", "null" })
public void typeDoesNotChangeValueAttribute() throws Exception {
    final String html = "<html>\n" + "<head></head>\n" + "<body>\n" + "  <input type='number' id='t'/>\n"
            + "  <button id='check' onclick='alert(document.getElementById(\"t\").getAttribute(\"value\"));'>"
            + "DoIt</button>\n" + "</body></html>";

    final WebDriver driver = loadPage2(html);
    final WebElement t = driver.findElement(By.id("t"));

    final WebElement check = driver.findElement(By.id("check"));
    check.click();
    verifyAlerts(driver, getExpectedAlerts()[0]);

    t.sendKeys("abc");
    check.click();
    verifyAlerts(driver, getExpectedAlerts()[1]);
}