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.hotwire.selenium.desktop.subscription.SubscriptionModuleFragment.java

License:Open Source License

public void typeZipcode(String zipCode) {
    WebElement emailElement = getWebDriver()
            .findElement(By.cssSelector(SUBSCRIPTION_MODULE + " input[name='zipCode']"));
    emailElement.clear();// w w  w  .ja  va  2s . c o m
    emailElement.sendKeys(zipCode);
}

From source file:com.hotwire.selenium.desktop.us.billing.AbstractBillingPage.java

License:Open Source License

public void selectAsUser(String sEmail, String sPassword) {
    WebElement signIn = getWebDriver().findElement(By.xpath("//img[@alt='Sign in']"));
    if (signIn != null) {
        WebElement email = getWebDriver().findElement(By.name("loginForm._NAE_email"));
        WebElement password = getWebDriver().findElement(By.name("loginForm._NAE_password"));
        email.sendKeys(sEmail);
        password.sendKeys(sPassword);//  w w  w  . ja va2 s  . c  o  m
        signIn.click();
        //...wait until Ajax is silent
        new Wait<>(new IsAjaxDone()).maxWait(15).apply(getWebDriver());
    }
}

From source file:com.hotwire.selenium.desktop.us.billing.car.impl.ccf.CcfPaymentMethodFragment.java

License:Open Source License

@Override
public CarPaymentMethod payPalUser(String firstName, String lastName) {
    WebElement payPalFirstName = getPayPalFirstName();
    WebElement payPalLastName = getPayPalLastName();
    payPalFirstName.clear();/*from  w w w .  j  a  v a  2  s  .  co m*/
    payPalFirstName.sendKeys(firstName);

    payPalLastName.clear();
    payPalLastName.sendKeys(lastName);
    return this;
}

From source file:com.hotwire.selenium.desktop.us.billing.onepage.HotelCreditCardFragment.java

License:Open Source License

public HotelCreditCardFragment withState(String state) {
    WebElement displayedElement = null;
    for (WebElement item : this.state) {
        if (item.isDisplayed() && item.isEnabled()) {
            displayedElement = item;/*  w ww  .j  a  v a2 s.  c o m*/
            break;
        }
    }
    if (displayedElement == null) {
        return this;
    }

    ExtendedSelect select = new ExtendedSelect(displayedElement);
    try {
        select.selectByIndex(Integer.parseInt(state));
        return this;
    } catch (NumberFormatException e) {
        // Do nothing. State is non-numeric and continue.
    }
    if (displayedElement != null) {
        if (displayedElement.getTagName().equals("select")) {
            new ExtendedSelect(displayedElement).selectIfVisibleTextStartsWithText(state);
        } else {
            // Default to sendkeys. Most likely element is an input text
            // area.
            displayedElement.sendKeys(state);
        }
    }
    // Else do nothing as this page is doing country specific elements and
    // some countries
    // will not have this element.
    return this;
}

From source file:com.hotwire.selenium.desktop.us.billing.onepage.HotelCreditCardFragment.java

License:Open Source License

public HotelCreditCardFragment withSavedState(String state) {
    WebElement displayedElement = null;
    for (WebElement item : this.savedState) {
        if (item.isDisplayed()) {
            displayedElement = item;// w  w w.  j  ava  2 s .  c  om
            break;
        }
    }
    if (displayedElement == null) {
        return this;
    }
    ExtendedSelect select = new ExtendedSelect(displayedElement);
    try {
        select.selectByIndex(Integer.parseInt(state));
        return this;
    } catch (NumberFormatException e) {
        // Do nothing. State is non-numeric and continue.
    }
    if (displayedElement != null) {
        if (displayedElement.getTagName().equals("select")) {
            new ExtendedSelect(displayedElement).selectIfVisibleTextStartsWithText(state);
        } else {
            // Default to sendkeys. Most likely element is an input text
            // area.
            displayedElement.sendKeys(state);
        }
    }
    // Else do nothing as this page is doing country specific elements and
    // some countries
    // will not have this element.
    return this;
}

From source file:com.hotwire.selenium.desktop.us.billing.onepage.HotelTravelerInfoFragment.java

License:Open Source License

public HotelBillingOnePage signInAsUser(String user, String password) {
    clickSignInLink();//from   w  w w  .j av  a 2 s  .  com
    WebElement email = getWebDriver().findElement(By.cssSelector(SIGN_IN_EMAIL));
    email.clear();
    email.sendKeys(user);
    WebElement passwd = getWebDriver().findElement(By.cssSelector(SIGN_IN_PASSWORD));
    passwd.clear();
    passwd.sendKeys(password);
    getWebDriver().findElement(By.cssSelector(SIGN_IN_SUBMIT)).click();
    return new HotelBillingOnePage(getWebDriver());
}

From source file:com.hotwire.selenium.desktop.us.results.car.fragments.fareFinder.CcfCarFareFinder.java

License:Open Source License

private void setText(WebElement webElement, String text) {
    webElement.clear();
    webElement.sendKeys(text);
}

From source file:com.hotwire.selenium.desktop.us.results.hotel.fragments.tripwatcher.HotelResultsTripwatcherLayerFragment.java

License:Open Source License

public void watchThisTrip(String newEmail) {
    if (newEmail.trim().equals("empty")) {
        newEmail = "";
    }/*from  w w  w  . j a  va2s. c o  m*/
    WebElement signupEmail = getVisibleTripWatcherEmailElement();
    signupEmail.clear();
    signupEmail.sendKeys(newEmail);
    getVisibleTripWatcherSubscribeButton().click();
    new WebDriverWait(getWebDriver(), EXTRA_WAIT)
            .until(PageObjectUtils.webElementVisibleTestFunction(By.cssSelector(".success"), true));
    assertThat(getWebDriver().findElement(By.cssSelector(".success")).getText()).contains(SUCCESSFUL_MESSAGE);
    closeButton.click();
}

From source file:com.hotwire.selenium.desktop.us.search.HotelSearchFragment.java

License:Open Source License

public void selectStartDate(Date startDate) {
    WebElement startDateField = getWebDriver().findElement(By.cssSelector(START_DATE));
    if (startDateField != null) {
        try {//from  w ww. j a  va 2  s . c  o  m
            new DatePicker(getWebDriver(), startDateField).selectDate(startDate);
        } catch (WebDriverException e) {
            LOGGER.info("Date picker issue for start date. Entering date manually.");
            SimpleDateFormat sdf = DatePicker.getSelectedCountryDateFormat(getWebDriver());
            startDateField.clear();
            startDateField.sendKeys(sdf.format(startDate));
        }
    } else {
        LOGGER.error("Start date field is not displayed on hotel landing page..");
    }
}

From source file:com.hotwire.selenium.desktop.us.search.HotelSearchFragment.java

License:Open Source License

public void selectEndDate(Date endDate) {
    WebElement endDateField = getWebDriver().findElement(By.cssSelector(END_DATE));
    if (endDateField != null) {
        try {/*  w w  w. j  av a  2 s . c  o  m*/
            new DatePicker(getWebDriver(), endDateField).selectDate(endDate);
        } catch (WebDriverException e) {
            LOGGER.info("Date picker issue for end date. Entering date manually.");
            SimpleDateFormat sdf = DatePicker.getSelectedCountryDateFormat(getWebDriver());
            endDateField.clear();
            endDateField.sendKeys(sdf.format(endDate));
        }
    } else {
        LOGGER.error("End date field is not displayed on hotel landing page..");
    }
}