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.easytox.automation.steps.LabClientImpl.java

@When("^Enter Location Name and the remaining details and click on 'Submit'$")
public void enter_location_name_and_the_remaining_details_and_click_on_submit() {
    WebElement labName = MyWebDriverUtils.findElement(driver, LAB_LOCATION_NAME_LOCATOR, LocatorType.NAME);
    if (labName != null) {
        labName.clear();//w ww .  ja  v  a  2 s  . c o m
        labName.sendKeys(LAB_LOCATION_NAME_VALUE);
    } else {
        Assert.fail("labName is null!");
    }

    WebElement labDepartment = MyWebDriverUtils.findElement(driver, LAB_LOCATION_DEPARTMENT_LOCATOR,
            LocatorType.NAME);
    if (labDepartment != null) {
        labDepartment.clear();
        labDepartment.sendKeys(LAB_LOCATION_DEPARTMENT_VALUE);
    } else {
        Assert.fail("labDepartment is null!");
    }

    WebElement labAddress = MyWebDriverUtils.findElement(driver, LAB_LOCATION_ADDRESS_LOCATOR,
            LocatorType.NAME);
    if (labAddress != null) {
        labAddress.clear();
        labAddress.sendKeys(LAB_LOCATION_ADDRESS_VALUE);
    } else {
        Assert.fail("labAddress is null!");
    }

    WebElement faxNumber = MyWebDriverUtils.findElement(driver, FAX_NUMBER_LOCATOR, LocatorType.NAME);
    if (faxNumber != null) {
        faxNumber.clear();
        faxNumber.sendKeys(FAX_NUMBER_VALUE);
    } else {
        Assert.fail("faxNumber is null!");
    }

    WebElement el = MyWebDriverUtils.findElement(driver, EDIT_SUBMIT_LOCATOR, LocatorType.CSS);
    WebDriverWait wait = new WebDriverWait(driver, TIME_OUT_IN_SECONDS);

    boolean flag = MyWebDriverUtils.waitInvisibilityOfElement(wait, CONTAINER_LOCATOR, LocatorType.ID);
    if (flag) {
        checkAndClick(el);
    } else {
        Assert.fail("flag is false!");
    }

}

From source file:com.easytox.automation.steps.LabClientImpl.java

@When("^Make required changes and click Update$")
public void make_required_changes_and_click_update() {
    WebElement labName = MyWebDriverUtils.findElement(driver, LAB_LOCATION_NAME_LOCATOR, LocatorType.NAME);
    if (labName != null) {
        labName.clear();//from  w  w  w  .j a v  a  2 s  . c o m
        labName.sendKeys(LAB_LOCATION_NAME_VALUE);
    } else {
        Assert.fail("labName is null!");
    }

    WebElement labDepartment = MyWebDriverUtils.findElement(driver, LAB_LOCATION_DEPARTMENT_LOCATOR,
            LocatorType.NAME);
    if (labDepartment != null) {
        labDepartment.clear();
        labDepartment.sendKeys(LAB_LOCATION_DEPARTMENT_VALUE);
    } else {
        Assert.fail("labDepartment is null!");
    }

    WebElement labAddress = MyWebDriverUtils.findElement(driver, LAB_LOCATION_ADDRESS_LOCATOR,
            LocatorType.NAME);
    if (labAddress != null) {
        labAddress.clear();
        labAddress.sendKeys(LAB_LOCATION_ADDRESS_VALUE);
    } else {
        Assert.fail("labAddress is null!");
    }

    WebElement faxNumber = MyWebDriverUtils.findElement(driver, FAX_NUMBER_LOCATOR, LocatorType.NAME);
    if (faxNumber != null) {
        faxNumber.clear();
        faxNumber.sendKeys(FAX_NUMBER_VALUE);
    } else {
        Assert.fail("faxNumber is null!");
    }

    WebElement el = MyWebDriverUtils.findElement(driver, UPDATE_SUBMIT_LOCATOR, LocatorType.CSS);
    WebDriverWait wait = new WebDriverWait(driver, TIME_OUT_IN_SECONDS);

    boolean flag = MyWebDriverUtils.waitInvisibilityOfElement(wait, CONTAINER_LOCATOR, LocatorType.ID);
    if (flag) {
        checkAndClick(el);
    } else {
        Assert.fail("flag is false!");
    }
}

From source file:com.easytox.automation.steps.LabClientImpl.java

@When("^Enter User information, Personal information and select lab information. click on 'Submit'$")
public void enter_information_and_submit() throws InterruptedException {
    Thread.sleep(TIME_STOP);/* w  w w. j  a v  a 2  s .  co m*/
    WebElement userName = MyWebDriverUtils.findElement(driver, USER_USERNAME_LOCATOR, LocatorType.NAME);
    if (userName != null) {
        userNameValue = StringUtils.generateRandom();
        userName.clear();
        userName.sendKeys(userNameValue);
    } else {
        Assert.fail("userName is null!");
    }

    WebElement password = MyWebDriverUtils.findElement(driver, USER_PASSWORD_LOCATOR, LocatorType.NAME);
    if (password != null) {
        password.clear();
        password.sendKeys(USER_PASSWORD_VALUE);
    } else {
        Assert.fail("password is null!");
    }

    WebElement firstName = MyWebDriverUtils.findElement(driver, USER_FIRST_NAME_LOCATOR, LocatorType.CSS);
    if (firstName != null) {
        firstName.clear();
        firstName.sendKeys(USER_FIRST_NAME_VALUE);
    } else {
        Assert.fail("firstName is null!");
    }

    WebElement lastName = MyWebDriverUtils.findElement(driver, USER_LAST_NAME_LOCATOR, LocatorType.CSS);
    if (lastName != null) {
        lastName.clear();
        lastName.sendKeys(USER_LAST_NAME_VALUE);
    } else {
        Assert.fail("lastName is null!");
    }

    WebElement email = MyWebDriverUtils.findElement(driver, USER_EMAIL_LOCATOR, LocatorType.NAME);
    if (email != null) {
        email.clear();
        email.sendKeys(USER_EMAIL_VALUE);
    } else {
        Assert.fail("email is null!");
    }

    WebElement phoneNumber = MyWebDriverUtils.findElement(driver, USER_PHONE_NUMBER_LOCATOR, LocatorType.NAME);
    if (phoneNumber != null) {
        phoneNumber.clear();
        phoneNumber.sendKeys(USER_PHONE_NUMBER_VALUE);
    } else {
        Assert.fail("phoneNumber is null!");
    }

    new Select(driver.findElement(By.cssSelector(SELECT_ROLE_LOCATOR))).selectByVisibleText(ROLE);

    new Select(driver.findElement(By.id(LAB_LOCATIONS_LOCATOR))).selectByVisibleText(LAB_LOCATIONS_VALUE);

    WebElement el = MyWebDriverUtils.findElement(driver, USER_SUBMIT_LOCATOR, LocatorType.CSS);
    WebDriverWait wait = new WebDriverWait(driver, TIME_OUT_IN_SECONDS);

    boolean flag = MyWebDriverUtils.waitInvisibilityOfElement(wait, CONTAINER_LOCATOR, LocatorType.ID);
    if (flag) {
        checkAndClick(el);
    } else {
        Assert.fail("flag is false!");
    }

}

From source file:com.easytox.automation.steps.LabClientImpl.java

@When("^Make changes to Personal Information and click update$")
public void make_changes_to_personal_information_and_click_update() {
    WebElement firstName = MyWebDriverUtils.findElement(driver, USER_FIRST_NAME_LOCATOR, LocatorType.CSS);
    if (firstName != null) {
        firstName.clear();// www .  j a v  a  2  s.  c  o m
        firstName.sendKeys(USER_FIRST_NAME_VALUE);
    } else {
        Assert.fail("firstName is null!");
    }

    WebElement lastName = MyWebDriverUtils.findElement(driver, USER_LAST_NAME_LOCATOR, LocatorType.CSS);
    if (lastName != null) {
        lastName.clear();
        lastName.sendKeys(USER_LAST_NAME_VALUE);
    } else {
        Assert.fail("lastName is null!");
    }

    WebElement email = MyWebDriverUtils.findElement(driver, USER_EMAIL_LOCATOR, LocatorType.NAME);
    if (email != null) {
        email.clear();
        email.sendKeys(USER_EMAIL_VALUE);
    } else {
        Assert.fail("email is null!");
    }

    WebElement phoneNumber = MyWebDriverUtils.findElement(driver, USER_PHONE_NUMBER_LOCATOR, LocatorType.NAME);
    if (phoneNumber != null) {
        phoneNumber.clear();
        phoneNumber.sendKeys(USER_PHONE_NUMBER_VALUE);
    } else {
        Assert.fail("phoneNumber is null!");
    }

    new Select(driver.findElement(By.id(LAB_LOCATIONS_LOCATOR))).selectByVisibleText(LAB_LOCATIONS_VALUE);

    WebElement el = MyWebDriverUtils.findElement(driver, UPDATE_BUTTON_LOCATOR, LocatorType.CSS);
    WebDriverWait wait = new WebDriverWait(driver, TIME_OUT_IN_SECONDS);

    boolean flag = MyWebDriverUtils.waitInvisibilityOfElement(wait, CONTAINER_LOCATOR, LocatorType.ID);
    if (flag) {
        checkAndClick(el);
    } else {
        Assert.fail("flag is false!");
    }

}

From source file:com.easytox.automation.steps.LabClientImpl.java

@Then("^Account locked message should be populated and user should not be able to login to application$")
public void account_locked_message_should_be_populated() {
    String currentUrl = driver.getCurrentUrl();
    Assert.assertEquals(currentUrl, LOGIN_PAGE_URL);

    WebElement element = driver.findElement(By.name(FIND_USERNAME));
    element.clear();//from ww w . j a v  a 2  s  . co m
    element.sendKeys(LOCK_USER);

    WebElement el = driver.findElement(By.name(FIND_LOGIN));
    el.clear();
    el.sendKeys(PASSWORD);

    driver.findElement(By.xpath(LOGIN_BUTTON_XPATH)).click();

    WebElement message = driver.findElement(By.cssSelector(LOCKED_MESSAGE_LOCATOR));
    Assert.assertTrue(message.isDisplayed());
}

From source file:com.easytox.automation.steps.LabClientImpl.java

@Then("^Notes should be opened for edit$")
public void notes_should_be_opened_for_edit() {
    WebElement note = MyWebDriverUtils.findElement(driver, NEW_NOTE_LOCATOR + "[" + 0 + "]", LocatorType.ID);
    if (note != null) {
        String noteValue = note.getAttribute(NOTE_UNLOCK_FOR_EDIT_LOCATOR);
        Assert.assertNotNull(noteValue);

        String noteClass = note.getAttribute(ATTRIBUTE_CLASS_LOCATOR);
        Assert.assertEquals(noteClass, NOTE_UNLOCK_FOR_EDIT_CLASS_VALUE);

        note.clear();//from w  ww  . java2  s.c  o m
        note.sendKeys(NEW_NOTE_VALUE);

        String value = note.getAttribute(ATTRIBUTE_VALUE_LOCATOR);
        Assert.assertEquals(value, NEW_NOTE_VALUE);

    } else {
        Assert.fail("note is null!");
    }

}

From source file:com.easytox.automation.steps.LabClientImpl.java

private void enterData(String locator, String value, LocatorType type) {
    WebElement field = MyWebDriverUtils.findElement(driver, locator, type);
    if (field != null) {
        field.clear();/*from  ww w .  ja va 2  s. c  om*/
        field.sendKeys(value);
    } else {
        Assert.fail("field is null!");
    }
}

From source file:com.easytox.automation.steps.LabClientImpl.java

private void enterData(String value, WebElement el, List<Boolean> list) {
    el.clear();
    el.sendKeys(value);
    list.add(checkTable());
}

From source file:com.easytox.automation.steps.LabClientImpl.java

private void authorization() {
    driver.navigate().to(LOGIN_PAGE_URL);

    WebElement element = driver.findElement(By.name(FIND_USERNAME));
    element.clear();//w  w  w  .ja  v  a2  s.  co  m
    element.sendKeys(LOGIN);

    WebElement el = driver.findElement(By.name(FIND_LOGIN));
    el.clear();
    el.sendKeys(PASSWORD);

    driver.findElement(By.xpath(LOGIN_BUTTON_XPATH)).click();
}

From source file:com.ecfeed.core.runner.java.SeleniumTestMethodInvoker.java

License:Open Source License

private void performActionClearAndSendKeys(WebElement webElement, String argument) {
    webElement.clear();
    webElement.sendKeys(argument);
}