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.citrix.g2w.webdriver.pages.BasePage.java

License:Open Source License

/**
 * method to clear element and enter text.
 *
 * @param elements//from w ww  .ja v a  2  s . c o  m
 *            (web element to clear)
 * @param text
 *            (value to send)
 */
public void clearAndType(final WebElement elements, final String text) {
    elements.clear();
    elements.sendKeys(text);
}

From source file:com.citrix.g2w.webdriver.pages.ScheduleAWebinarPage.java

License:Open Source License

/**
 * Method used to publish values for corresponding text box Id.
 * //from w w  w  . java  2  s  .c  om
 * @param id
 *            (get id of text box to publish value)
 * @param value
 *            (publish value for corresponding ID)
 */
private void setTextBoxValue(final String id, final String value) {
    JavascriptExecutor js = (JavascriptExecutor) this.driver;
    StringBuilder script = new StringBuilder();
    script.append("var element = document.getElementById('" + id + "');");
    script.append("element.value='" + value + "';");
    WebElement textBox = this.driver.findElement(By.id(id));
    if (this.driver instanceof HtmlUnitDriver) {
        js.executeScript(script.toString());
        textBox.sendKeys("");
    } else {
        script.append("element.dispatchEvent(new Event('change'))");
        js.executeScript(script.toString());
    }
}

From source file:com.coderoad.automation.common.util.old.BasePage.java

License:Open Source License

/**
 * this method sets the text in the webelement.
 * //from   ww w  .  j  a  v  a 2s.  c o m
 * @param fieldName the field name
 * @param value the value
 */
protected void setText(WebElement fieldName, String value) {

    clearText(fieldName);
    fieldName.clear();
    if (value != null) {
        fieldName.sendKeys(value);
    }
}

From source file:com.coderoad.automation.common.util.old.BasePage.java

License:Open Source License

public String getVersion(Enum<Modules> portal) {
    String response = null;/*from w ww.  j a v  a2s  .  c  o  m*/
    try {
        if (portal == Modules.CONSUMER_MENU) {
            WebElement html = driver.findElement(By.tagName("html"));
            Assert.assertTrue("The page is not displayed.", html != null);
            String selectAll = Keys.chord(Keys.CONTROL, Keys.SHIFT, "v");
            html.sendKeys(selectAll);
            Alert alertVersion = driver.switchTo().alert();
            response = alertVersion.getText().split(":")[1];
            alertVersion.accept();
        } else if (portal == Modules.MOBILE_PORTAL) {
            WebElement element = driver.findElement(By.xpath("//div[contains(@class, 'site-version')]"));
            Actions actions = new Actions(driver);
            Action doubleClick = actions.doubleClick(element).build();
            doubleClick.perform();
            Alert alertVersion = driver.switchTo().alert();
            response = alertVersion.getText();
            alertVersion.accept();
        }

    } catch (Exception e) {
        e.printStackTrace();
        response = null;
    }
    return response;
}

From source file:com.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Clear and set text.//w  w w.j  a  v a2 s. c o  m
 * 
 * @param driver the driver
 * @param locator the locator
 * @param innerText the inner text
 * @param timeout the timeout
 */
public static void clearAndSetText(final WebDriver driver, final By locator, final String innerText,
        final Timeout timeout) {

    final WebElement element = getElement(driver, locator, timeout);
    Assert.assertNotNull(element, "Element cannot be null");
    element.clear();
    element.sendKeys(innerText);
    element.sendKeys(Keys.ENTER);
    WaitUtil.waitUntil(Timeout.ATOMIC_TIMEOUT);
}

From source file:com.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Clear and set text press enter./*from   ww  w.  j  a va  2 s . co  m*/
 * 
 * @param driver the driver
 * @param locator the locator
 * @param innerText the inner text
 * @param timeout the timeout
 */
public static void clearAndSetTextPressEnter(final WebDriver driver, final By locator, final String innerText,
        final Timeout timeout) {

    final WebElement element = getElement(driver, locator, timeout);
    element.clear();
    element.sendKeys(innerText);
    element.sendKeys(Keys.ENTER);
}

From source file:com.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Clear text./*  ww w .java  2s.c  o m*/
 * 
 * @param driver the driver
 * @param locator the locator
 * @param timeout the timeout
 */
public static void clearText(final WebDriver driver, final By locator, final Timeout timeout) {

    final WebElement element = getElement(driver, locator, timeout);
    element.clear();
    element.sendKeys(Keys.ENTER);
}

From source file:com.coderoad.automation.rocketTruedx.RocketTruedxNaBasePage.java

License:Open Source License

/**
 * Verify phone number validation./* w  ww  . j  a  v  a  2s. com*/
 * 
 * @param xpathInputPhoneNumber the xpath input phone number
 * @param phone the phone
 * @param typeValidation the type validation
 */
public void verifyPhoneNumberValidation(String xpathInputPhoneNumber, String phone, String typeValidation) {

    WaitUtil.waitUntil(3);
    WebElement element = driver.findElement(By.xpath(xpathInputPhoneNumber));
    element.clear();
    element.sendKeys(phone);
    element = driver.findElement(By.xpath(xpathInputPhoneNumber));
    Assert.assertTrue(
            element.getAttribute("aria-invalid").contains(typeValidation.equals("1") ? "false" : "true"),
            "The validation does not function correctly.");
    LogUtil.log("The validation functions correctly.", LogLevel.LOW);
}

From source file:com.cognifide.aet.sanity.functional.cucumber.FilteringSteps.java

License:Apache License

@When("^I search for tests containing \"([^\"]*)\"$")
public void iSearchForTestsContaining(final String searchedTerm) throws Throwable {
    Aside aside = reportHomePage.getAside();
    final WebElement searchInput = aside.getSearchInput();

    // retries typing as there is known bug in selenium:
    // https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4446
    bobcatWait.withTimeout(Timeouts.MEDIUM).until(new ExpectedCondition<Boolean>() {

        @Nullable//from   w  w  w.  j av a2  s .co m
        @Override
        public Boolean apply(@Nullable WebDriver input) {
            searchInput.clear();
            searchInput.sendKeys(searchedTerm);
            return searchInput.getAttribute("value").equals(searchedTerm);
        }
    });
}

From source file:com.coinbot.captcha.SolveMedia.java

License:Open Source License

@Override
public void answerToInput(WebDriver driver) {
    WebElement input = driver.findElement(By.id("adcopy_response"));
    input.sendKeys(getAnswer());
}