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:authentication.AccountInfo.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

    WebDriver driver = new ChromeDriver();
    driver.get(//from  w w w  .  j av a 2 s .  c o m
            "https://www.facebook.com/?stype=lo&jlou=Afeo3usnUHyB5AT4TqVF4PpoNba5Ld2sOALGhGMfhib8xyeI0FjYqdYf72ZtVncLyfHnYBBU6pY3XZ_l-D-KchQXCwLecdkAemJcXs_dIu-UmQ&smuh=16711&lh=Ac-txP8J-TK6lCJ5");
    WebElement username = driver.findElement(By.id("email"));
    WebElement password = driver.findElement(By.id("pass"));
    username.sendKeys(b.getUserName());
    password.sendKeys(b.getPassWord());
    WebElement button = driver.findElement(By.id("loginbutton"));
    button.click();
}

From source file:authentication.TestingTable.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
    WebDriver driver = new ChromeDriver();
    driver.get(/*from   w  w  w  .j a  v  a2s.  co m*/
            "https://www.facebook.com/?stype=lo&jlou=Afeo3usnUHyB5AT4TqVF4PpoNba5Ld2sOALGhGMfhib8xyeI0FjYqdYf72ZtVncLyfHnYBBU6pY3XZ_l-D-KchQXCwLecdkAemJcXs_dIu-UmQ&smuh=16711&lh=Ac-txP8J-TK6lCJ5");
    WebElement username = driver.findElement(By.id("email"));
    WebElement password = driver.findElement(By.id("pass"));
    password.sendKeys(model.getValueAt(jTable1.getSelectedRow(), 0).toString());
    username.sendKeys(model.getValueAt(jTable1.getSelectedRow(), 1).toString());
    WebElement button = driver.findElement(By.id("loginbutton"));
    button.click();
}

From source file:backend.MakeUserTest.java

private void textInput(String elementID, String value) {
    WebElement inputElement = driver.findElement(By.id(elementID));
    inputElement.sendKeys(value);
}

From source file:be.rubus.web.jerry.recording.RecordValueTest.java

License:Apache License

@Test
@RunAsClient/* ww w  .  ja  v  a2s  .  c  o m*/
public void testClassLevelValidation() throws Exception {
    driver.get(new URL(contextPath, "dateRange.xhtml").toString());

    WebElement field = driver.findElement(By.id("test:beginDate"));
    field.sendKeys("01/03/2015");

    field = driver.findElement(By.id("test:endDate"));
    field.sendKeys("01/01/2015");

    WebElement submitButton = driver.findElement(By.id("test:submit"));
    submitButton.click();

    Thread.sleep(1000);

    WebElement messages = driver.findElement(By.id("errors"));
    List<WebElement> errorElements = messages.findElements(By.tagName("li"));

    // FIXME The test fails and it seems that RecordingInfoPhaseListener doesn't kick in
    assertThat(errorElements).hasSize(1);

    assertThat(errorElements.get(0).getText()).contains("Validation Error: Value is required.");

}

From source file:be.rubus.web.jerry.validation.CustomTest.java

License:Apache License

@Test
@RunAsClient/*  w w w.j  av a  2 s.c  o m*/
public void testCustom() throws Exception {
    driver.get(new URL(contextPath, "custom.xhtml").toString());

    WebElement element = driver.findElement(By.id("test:zipCodeMaskLabel"));
    String text = element.getText();
    assertThat(text).isEqualTo("Zip code (mask)*");

    element = driver.findElement(By.id("test:zipCode"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("4");

    element = driver.findElement(By.id("test:zipCodeMask"));

    element.sendKeys("azer");
    // Only numbers allowed in the mask
    assertThat(element.getAttribute("value")).isEqualTo("____");

    element.clear();
    element.sendKeys("12345");
    // Only 4 numbers allowed in the mask
    assertThat(element.getAttribute("value")).isEqualTo("1234");

}

From source file:be.rubus.web.jerry.validation.FutureDateProviderTest.java

License:Apache License

@Test
@RunAsClient/*from   ww  w .jav  a 2  s  .  c om*/
public void testFuture() throws Exception {
    driver.get(new URL(contextPath, "future.xhtml").toString());

    //By default, the date provider is using system date, so failures
    WebElement date1 = driver.findElement(By.id("test:date1"));
    date1.sendKeys("23/02/2015");

    WebElement date2 = driver.findElement(By.id("test:date2"));
    date2.sendKeys("23/02/2015");

    assertThat(date1.getAttribute("class")).doesNotContain("ui-state-error");
    assertThat(date2.getAttribute("class")).doesNotContain("ui-state-error");

    WebElement btn = driver.findElement(By.id("test:submit"));
    btn.click();

    WebElement errors = driver.findElement(By.id("errors"));

    List<WebElement> errorMessages = errors.findElements(By.tagName("li"));
    assertThat(errorMessages).hasSize(2);

    // Page is reloaded so elements are detached

    date1 = driver.findElement(By.id("test:date1"));
    date2 = driver.findElement(By.id("test:date2"));

    assertThat(date1.getAttribute("class")).contains("ui-state-error");
    assertThat(date2.getAttribute("class")).contains("ui-state-error");

    // Set date for DateProvider
    WebElement fixedNow = driver.findElement(By.id("date:fixedNow"));
    fixedNow.clear();
    fixedNow.sendKeys("20/02/2015");

    WebElement dateBtn = driver.findElement(By.id("date:setDate"));
    dateBtn.click();

    date1 = driver.findElement(By.id("test:date1"));
    date1.sendKeys("23/02/2015");

    date2 = driver.findElement(By.id("test:date2"));
    date2.sendKeys("23/02/2015");

    btn = driver.findElement(By.id("test:submit"));
    btn.click();

    errors = driver.findElement(By.id("errors"));

    errorMessages = errors.findElements(By.tagName("li"));
    assertThat(errorMessages).hasSize(1); // Only 1 error now

    // Page is reloaded so elements are detached

    date1 = driver.findElement(By.id("test:date1"));
    date2 = driver.findElement(By.id("test:date2"));

    assertThat(date1.getAttribute("class")).contains("ui-state-error");
    assertThat(date2.getAttribute("class")).doesNotContain("ui-state-error"); // The one withValFuture

}

From source file:be.rubus.web.jerry.validation.FutureTest.java

License:Apache License

@Test
@RunAsClient/* w  w w . j  a  va 2  s .c  om*/
public void testFuture() throws Exception {
    driver.get(new URL(contextPath, "future_NoProvider.xhtml").toString());

    WebElement date1 = driver.findElement(By.id("test:date1"));
    date1.sendKeys("23/02/2015");

    WebElement date2 = driver.findElement(By.id("test:date2"));
    date2.sendKeys("23/02/2015");

    WebElement btn = driver.findElement(By.id("test:submit"));
    btn.click();

    WebElement errors = driver.findElement(By.id("errors"));

    List<WebElement> errorMessages = errors.findElements(By.tagName("li"));
    assertThat(errorMessages).hasSize(2);

    // Page is reloaded so elements are detached

    date1 = driver.findElement(By.id("test:date1"));
    date2 = driver.findElement(By.id("test:date2"));

    assertThat(date1.getAttribute("class")).contains("ui-state-error");
    assertThat(date2.getAttribute("class")).contains("ui-state-error");
}

From source file:be.rubus.web.jerry.validation.MaxSizeTest.java

License:Apache License

@Test
@RunAsClient//from w ww .  ja  va  2s  . com
public void testMaxLength_TextArea() throws Exception {
    driver.get(new URL(contextPath, "maxSize_TextArea.xhtml").toString());

    WebElement element = driver.findElement(By.id("frm:description"));

    WebElement remaining = driver.findElement(By.id("frm:remaining"));
    assertThat(remaining.getText()).contains("10");

    element.sendKeys("abcde");
    assertThat(remaining.getText()).contains("5");

    element.sendKeys("abcdefghijk");
    assertThat(remaining.getText()).contains("0");

    assertThat(element.getAttribute("value")).isEqualTo("abcdeabcde");

}

From source file:be.ugent.mmlab.webdriver.Demo.java

License:Apache License

public void demoTime() throws InterruptedException {
    // initialize web browser.
    WebDriver driver = new FirefoxDriver();

    // go to the Belgian railways website
    driver.get("http://www.belgianrail.be");

    // select "English"
    // HTML:/*from w  w w.  j  a  v  a2s  .c om*/
    // <a
    //   id="ctl00_bodyPlaceholder_languagesList_ctl02_languageNameLink"
    //   href="javascript:__doPostBack('ctl00$bodyPlaceholder$languagesList$ctl02$languageNameLink','')"
    // > English </a>
    WebElement english = driver
            .findElement(By.id("ctl00_bodyPlaceholder_languagesList_ctl02_languageNameLink"));
    english.click();

    // fill out departure
    WebElement from = driver.findElement(By.id("departureStationInput"));
    from.sendKeys("Gent-Dampoort");

    // pause for a second to make it not too fast
    Thread.sleep(1000);
    // click in the field to get the auto-completion away
    from.click();

    // fill out arrival
    WebElement to = driver.findElement(By.id("arrivalStationInput"));
    to.sendKeys("Brussel-Noord");

    Thread.sleep(1000);
    to.click();

    // click timetable button
    WebElement timetableButton = driver.findElement(By.id(
            "ctl00_ctl00_bodyPlaceholder_bodyPlaceholder_mobilityTimeTableSearch_HomeTabTimeTable1_submitButton"));
    timetableButton.click();

    // get departure info
    // HTML:
    // <td headers="hafasOVTimeOUTWARD" class="time">
    //    <div>
    //     <div class="planed overviewDep">
    //      10:00 dep <span class="bold prognosis">+12 min.</span>
    //     </div>
    //     <div class="planed">
    //      11:20 arr <span class="bold green">+0 min.</span>
    //     </div>
    //   </div>
    // </td>
    List<WebElement> timeCells = driver.findElements(By.className("time"));
    for (WebElement timeCell : timeCells) {
        List<WebElement> times = timeCell.findElements(By.className("planed"));
        System.out.println("----------------------------------------------");
        System.out.println("departure time: " + times.get(0).getText());
        System.out.println("arrival time:   " + times.get(1).getText());
    }
}

From source file:bingbot.BingBot.java

/**
 * @param n number of searches to execute
 * @param file file to get user data from
 * @throws java.io.IOException//from   w  ww .  j  a va2 s.  c  om
 * @throws java.lang.InterruptedException
 */
public void search(int m, int n, File file) throws Exception {
    System.out.println("Search method entered...");

    scanner = new Scanner(file);
    Scanner sc = new Scanner(new File("./files/dict"));

    String next = scanner.next();
    String name = null;
    String password = null;
    while (!next.equals("END")) {
        name = next;
        password = scanner.next();
        next = scanner.next();
    }

    for (int k = 0; k < m; k++) {

        driver.get("http://live.com");
        try {
            WebElement signout = driver.findElement(By.id("c_signout"));
            if (!signout.isDisplayed()) {
                return;
            }

        } catch (Exception e) {
            System.out.println("NO SUCH ELEMENT 'C_SIGNOUT'");
            System.out.println("SIGNING IN");

        }

        WebElement username = driver.findElement(By.id("i0116"));
        username.sendKeys(name);
        WebElement userpassword = driver.findElement(By.id("i0118"));
        userpassword.sendKeys(password);
        WebElement signin = driver.findElement(By.id("idSIButton9"));
        signin.click();
        Thread.sleep(10000);
        for (int j = 0; j < 41238; j++) {
            String word = sc.next();
            list[j] = word;
        }
        for (int i = 0; i < n; i++) {
            Random rand = new Random();
            driver.get("https://bing.com/");
            WebElement query = driver.findElement(By.id("sb_form_q"));
            query.sendKeys(list[rand.nextInt(41238)]);
            WebElement go = driver.findElement(By.id("sb_form_go"));
            go.click();
            Thread.sleep(rand.nextInt(5000) + 5000);
        }
    }
    seleniumServer.stop();
}