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.demo.selenium.example.GridExampleTest.java

License:Apache License

@Test
public void GridTwoNodeTest() throws MalformedURLException, InterruptedException {

    DesiredCapabilities aDesiredcap = DesiredCapabilities.chrome();
    WebDriver dr = new RemoteWebDriver(new URL("http://172.19.6.46:5555/wd/hub"), aDesiredcap);
    dr.get("http://www.baidu.com");
    dr.manage().window().maximize();/*from w  w w  .j  av a 2 s . co m*/

    String str[] = new String[] { "java", "selenium", "spring", "mybatis", "jps", "grid", "mysql", "iphone" };
    for (String string : str) {
        WebElement element = dr.findElement(By.xpath(".//*[@id='kw']"));
        element.clear();
        element.sendKeys(string);

        Thread.sleep(1000);

        WebElement buttons = dr.findElement(By.xpath(".//*[@id='su']"));

        System.out.println(buttons.getTagName());

        buttons.click();
    }

    Thread.sleep(2000);

    dr.close();

}

From source file:com.digi.selenium.util.common.PageNavigation.java

protected void signInWithMSSIDN(String countryPrefix, String mssidn, String Password) {
    // try{/*from   w  w w.ja  va  2  s. c  om*/
    loadPage(AppConstants.DIGI_LOGIN_PAGE_PROD);
    waitForPageLoad(30);

    WebElement loginElement = getDriver().findElement(By.id("signIn"));
    loginElement.sendKeys(Keys.ENTER);
    waitForPageLoad(60);
    handleLink_ByText(AppConstants.DIGI_LOGIN_WITHPHONENUM);
    handleClearInputField_ByName("cc");
    handleInputField_ByName("cc", countryPrefix);
    handleInputField_ByName("number", mssidn);
    handleInputField_ByName("password", Password);
    handleButtonClick_ByID("inst_button_msisdn-login_form_login");

    /*} catch(Exception e){
       log.error("Fail : "+e.toString());
       throw(e);
    }*/
}

From source file:com.digi.selenium.util.common.PageNavigation.java

protected void signInWithMSSIDN_stage(String countryPrefix, String mssidn, String Password) {
    // try{//from   ww w .j a v a  2s . c o m
    loadPage(AppConstants.DIGI_LOGIN_PAGE_STAGE);
    waitForPageLoad(30);

    WebElement loginElement = getDriver().findElement(By.id("signIn"));
    loginElement.sendKeys(Keys.ENTER);
    waitForPageLoad(60);

    handleLink_ByText(AppConstants.DIGI_LOGIN_WITHPHONENUM);
    handleClearInputField_ByName("cc");
    handleInputField_ByName("cc", countryPrefix);
    handleInputField_ByName("number", mssidn);
    handleInputField_ByName("password", Password);
    handleButtonClick_ByID("inst_button_msisdn-login_form_login");
    /*} catch(Exception e){
       log.error("Fail : "+e.toString());
       throw(e);
    }*/
}

From source file:com.digi.selenium.util.PageNavigation.java

protected void signInWithMSSIDN_stage(String countryPrefix, String mssidn, String Password) {
    try {/*from   w  w  w  .j  a  v  a  2 s.c om*/
        loadPage(AppConstants.DIGI_LOGIN_PAGE_STAGE);
        waitForPageLoad(30);
        WebElement loginElement = getDriver().findElement(By.id("signIn"));
        loginElement.sendKeys(Keys.ENTER);
        waitForPageLoad(60);
        handleLink_ByText(AppConstants.DIGI_LOGIN_WITHPHONENUM);
        handleClearInputField_ByName("cc");
        handleInputField_ByName("cc", countryPrefix);
        handleInputField_ByName("number", mssidn);
        handleInputField_ByName("password", Password);
        handleButtonClick_ByID("inst_button_msisdn-login_form_login");
    } catch (Exception e) {
        log.error("Fail : Login Failur for MSSIDN  :" + mssidn);
        shutDown();
    }
}

From source file:com.dukescript.api.selenium.ElementTests.java

License:Open Source License

@Test
public void enabledTest() throws InterruptedException {
    WebElement input = driver.findElement(By.id("input"));
    WebElement button = driver.findElement(By.id("button"));
    Assert.assertEquals(false, button.isEnabled());
    String value = input.getAttribute("value");
    input.sendKeys("Hallo");
    Thread.sleep(500);/*w  w w . jav  a2  s .c  o m*/
    Assert.assertEquals(true, button.isEnabled());
}

From source file:com.dukescript.api.selenium.ExternalWebViewTest.java

License:Open Source License

@Test
public void withModelAndExistingWebView() throws InterruptedException {
    WebElement element = driver.findElement(By.id("target"));
    Assert.assertEquals("Hello", element.getText());
    WebElement button = driver.findElement(By.id("button"));
    button.click();/*from  ww w . j  a v a 2  s.  co m*/
    Assert.assertEquals("World", element.getText());
    WebElement input = driver.findElement(By.id("input"));
    input.clear();
    input.sendKeys("DukeScript");
    button.click();
    Assert.assertEquals("DukeScript", element.getText());
    WebElement findElement = driver.findElement(By.cssSelector(".bla"));
    Assert.assertNotNull(findElement);
    Assert.assertEquals("DukeScript", findElement.getText());
    List<WebElement> findElements = driver.findElements(By.cssSelector(".bla"));
    Assert.assertEquals(1, findElements.size());
}

From source file:com.dukescript.api.selenium.FindsByTest.java

License:Open Source License

@Test
public void withModel() {
    // please note that this method is not executed in BrwsrCtx
    // to allow seeing updates in the Browser while debugging a test
    WebElement element = driver.findElement(By.id("target"));
    Assert.assertEquals("Hello", element.getText());
    WebElement button = driver.findElement(By.id("button"));
    button.click();//from   ww  w  . j  ava2s  . c om
    Assert.assertEquals("World", element.getText());
    WebElement input = driver.findElement(By.id("input"));
    input.clear();
    input.sendKeys("DukeScript");
    button.click();
    Assert.assertEquals("DukeScript", element.getText());
    WebElement findElement = driver.findElement(By.cssSelector(".bla"));
    Assert.assertNotNull(findElement);
    Assert.assertEquals("DukeScript", findElement.getText());
}

From source file:com.easytox.automation.steps.addPhysicians.AddPhysiciansQuestSteps.java

@Given("^User should be login to the lab$")
public void user_should_be_login_to_the_lab() throws Throwable {
    driver.navigate().to(URL);/*from   ww  w  .  j a  va2s .com*/

    WebElement username = driver.findElement(By.name(FIND_USERNAME));
    username.clear();
    username.sendKeys(USERNAME);

    WebElement psw = driver.findElement(By.name(FIND_PASSWORD));
    psw.clear();
    psw.sendKeys(PASSWORD);

    driver.findElement(By.xpath("//*[@id=\"loginform\"]/div[3]/div/button")).click();
}

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

@When("^Enter all the information in the screen and click Submit$")
public void enter_all_the_information_in_the_screen_and_click_submit() {
    WebElement business = MyWebDriverUtils.findElement(driver, BUSINESS_NAME_LOCATOR, LocatorType.NAME);
    if (business != null) {
        business.clear();//from w ww .  j a va 2 s .co m
        business.sendKeys(BUSINESS_NAME_VALUE);
    } else {
        Assert.fail("business is null!");
    }

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

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

    WebElement zipCode = MyWebDriverUtils.findElement(driver, ZIP_LOCATOR, LocatorType.ID);
    if (zipCode != null) {
        zipCode.clear();
        zipCode.sendKeys(ZIP_VALUE);
    } else {
        Assert.fail("zipCode is null!");
    }

    WebElement city = MyWebDriverUtils.findElement(driver, CITY_LOCATOR, LocatorType.ID);
    if (city != null) {
        city.clear();
        city.sendKeys(CITY_VALUE);
    } else {
        Assert.fail("city is null!");
    }

    WebElement state = MyWebDriverUtils.findElement(driver, STATE_LOCATOR, LocatorType.ID);
    if (state != null) {
        state.clear();
        state.sendKeys(STATE_VALUE);
    } else {
        Assert.fail("state is null!");
    }

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

    WebElement contactNumber = MyWebDriverUtils.findElement(driver, CONTACT_NUMBER_LOCATOR, LocatorType.NAME);
    if (contactNumber != null) {
        contactNumber.clear();
        contactNumber.sendKeys(CONTACT_NUMBER_VALUE);
    } else {
        Assert.fail("contactNumber 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 contactEmail = MyWebDriverUtils.findElement(driver, CONTACT_EMAIL_LOCATOR, LocatorType.NAME);
    if (contactEmail != null) {
        contactEmail.clear();
        contactEmail.sendKeys(CONTACT_EMAIL_VALUE);
    } else {
        Assert.fail("contactEmail is null!");
    }

    WebElement submit = MyWebDriverUtils.findElement(driver, SUBMIT_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(submit);
    } else {
        Assert.fail("flag is false!");
    }

}

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

@When("^Make changes as needed and click update$")
public void make_changes_as_needed_and_click_update() {

    WebElement address1 = MyWebDriverUtils.findElement(driver, ADDRESS_1_LOCATOR, LocatorType.NAME);
    if (address1 != null) {
        address1.clear();//  w  ww . j a v  a 2  s.co  m
        address1.sendKeys(ADDRESS_1_VALUE);
    } else {
        Assert.fail("address1 is null!");
    }

    WebElement address2 = MyWebDriverUtils.findElement(driver, ADDRESS_2_LOCATOR, LocatorType.NAME);
    if (address2 != null) {
        address2.clear();
        address2.sendKeys(ADDRESS_2_VALUE);
    } else {
        Assert.fail("address2 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 submit = MyWebDriverUtils.findElement(driver, SUBMIT_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(submit);
    } else {
        Assert.fail("flag is false!");
    }
}