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.algomedica.service.AlgomedicaTest.java

@Test
public void NewCustomerCreation() throws InterruptedException {

    driver.findElement(By.cssSelector("[class='btn btn-success pull-left']")).click();

    WebElement orgName = driver.findElement(By.id("orgName"));
    orgName.sendKeys("Apollo");

    WebElement personName = driver.findElement(By.id("personName"));
    personName.sendKeys("rakesh");

    WebElement personEmailId = driver.findElement(By.id("personEmailId"));
    personEmailId.sendKeys("rakesh.pandey@silicus.com");

    WebElement contact1 = driver.findElement(By.id("contact1"));
    contact1.sendKeys("9873459870");

    WebElement contact2 = driver.findElement(By.id("contact2"));
    contact2.sendKeys("9345098789");

    WebElement country = driver.findElement(By.id("country"));
    country.sendKeys("India");

    WebElement city = driver.findElement(By.id("city"));
    city.sendKeys("Pune");

    WebElement State = driver.findElement(By.id("State"));
    State.sendKeys("Maharashtra");

    WebElement PIN = driver.findElement(By.id("PIN"));
    PIN.sendKeys("83459");

    WebElement address1 = driver.findElement(By.id("address1"));
    address1.sendKeys("RH no #92");

    WebElement address2 = driver.findElement(By.id("address2"));
    address2.sendKeys("RH no #93");

    driver.findElement(By.cssSelector("[class='btn btn-success ng-scope']")).click();

}

From source file:com.algomedica.service.AlgomedicaTest.java

@Test
public void NewMachineDetails() throws InterruptedException {

    driver.findElement(By.cssSelector("[class='btn btn-primary pull-left']")).click();

    WebElement MACNo = driver.findElement(By.id("MACNo"));
    MACNo.sendKeys("985921113716");

    WebElement DeviceModel = driver.findElement(By.id("Device Model #"));
    DeviceModel.sendKeys("Dell Thinkpad");

    WebElement DeviceBrandName = driver.findElement(By.id("Device Brand Name"));
    DeviceBrandName.sendKeys("Dell");

    Select lsType = new Select(driver.findElement(By.xpath(
            ".//*[@id='page-wrapper1']/div[3]/div/div[2]/div/div[2]/div[3]/div/form/fieldset/div[2]/div[1]/div/select")));
    ;/* w ww. ja  va  2  s.  c o  m*/
    lsType.selectByVisibleText("Trial");

    Select LicenseCategory = new Select(driver.findElement(By.xpath(
            ".//*[@id='page-wrapper1']/div[3]/div/div[2]/div/div[2]/div[3]/div/form/fieldset/div[2]/div[2]/div/select")));
    LicenseCategory.selectByVisibleText("Small");

    WebElement LicenseValidity = driver.findElement(By.id("License Validity"));
    LicenseValidity.sendKeys("30");

    WebElement LicenseCost = driver.findElement(By.id("License Cost"));
    LicenseCost.sendKeys("99");

    WebElement salesOpsName = driver.findElement(By.id("Sales Ops Personnel Name"));
    salesOpsName.sendKeys("rahul");

    WebElement SendEmailTo = driver.findElement(By.id("Send Email To"));
    SendEmailTo.sendKeys("rakesh.pandey@silicus.com");

    driver.findElement(By.cssSelector("[class='btn btn-success ng-scope']")).click();

    Thread.sleep(3000);
    driver.findElement(By.cssSelector("button[class='close']")).click();

    Thread.sleep(3000);
    driver.findElement(By.xpath(".//*[@id='wrapper']/nav/ul/li[1]/a")).click();

    Thread.sleep(3000);
    driver.findElement(By.xpath(".//*[@id='wrapper']/nav/ul/li[2]/a")).click();

    Thread.sleep(3000);
    driver.close();

}

From source file:com.amazon.alexa.avs.AVSApp.java

License:Open Source License

/**
 * Performs amazon LWA login using the given <tt>driver</tt>.
 * // w  w  w  .j av  a  2 s.c o  m
 * @param driver Driver which is already configured to LWA login page.
 */
private void authenticate(final WebDriver driver) {
    log.debug("Title : {}", driver.getTitle());
    new WebDriverWait(driver, 1000)
            .until(ExpectedConditions.and(ExpectedConditions.presenceOfElementLocated(By.id("ap_email")),
                    ExpectedConditions.presenceOfElementLocated(By.id("ap_password"))));
    log.info("Auto logging in to LWA");
    final WebElement username = driver.findElement(By.id("ap_email"));
    final WebElement password = driver.findElement(By.id("ap_password"));
    username.sendKeys(deviceConfig.getLWAUsername());
    password.sendKeys(deviceConfig.getLWAPassword());
    final WebElement button = driver.findElement(By.tagName("button"));
    button.click();
}

From source file:com.arifnazarpurwandaru.selenium.MainFrame.java

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

    try {//from   w ww.j  a va  2 s .  c  om
        //            MarionetteDriverManager.getInstance().setup();
        System.out.println("Mulai Pencarian...");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM Firefox.exe");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");

        WebDriver driver = null;
        String kereta = ((ComboItem) comboKereta.getSelectedItem()).getValue();

        //use proxy
        if (radioUseProxy.isSelected()) {
            String proxyHost = hostProxy.getText() + ":" + portProxy.getText();
            Proxy proxy = new Proxy();
            proxy.setHttpProxy(proxyHost);
            proxy.setSslProxy(proxyHost);
            proxy.setFtpProxy(proxyHost);
            proxy.setSocksUsername(usernameProxy.getText());
            proxy.setSocksPassword(new String(passwordProxy.getPassword()));

            DesiredCapabilities cap = new DesiredCapabilities();
            cap.setCapability(CapabilityType.PROXY, proxy);

            driver = new ChromeDriver(cap);
        } else {

            //                    driver = new MarionetteDriver();
            driver = new ChromeDriver();
        }
        //       hmin = Integer.valueOf(args[0]).intValue();
        ComboItem link = (ComboItem) comboLink.getSelectedItem();
        driver.get(link.getValue());
        List<WebElement> list = null;
        int counter = 1;
        boolean keeploop = true;
        while (/**list==null || list.size() == 0**/
        keeploop) {

            try {
                Select selectTgl = new Select(driver.findElement(By.name("tanggal")));
                selectTgl.selectByIndex(comboTanggal.getSelectedIndex());

                ComboItem stFrom = (ComboItem) comboStBerangkat.getSelectedItem();
                Select selectFrom = new Select(driver.findElement(By.name("origination")));
                selectFrom.selectByValue(stFrom.getValue());

                ComboItem stTo = (ComboItem) comboStTujuan.getSelectedItem();
                Select selectTo = new Select(driver.findElement(By.name("destination")));
                selectTo.selectByValue(stTo.getValue());

                Select selectAdult = new Select(driver.findElement(By.name("adult")));
                selectAdult.selectByValue("1");

                WebElement element = driver.findElement(By.name("Submit"));
                element.click();
                //          Thread.sleep(1000);
                //tunggu sampe page ready, nandainnya kalo element div dengan css class "itReservationContent" muncul
                WebElement elementForWait = (new WebDriverWait(driver, 1)).until(
                        ExpectedConditions.visibilityOfElementLocated(By.className("itReservationContent")));
                //end wait

                list = driver.findElements(By.className("itButton"));
                if (list != null && list.size() > 0) {
                    List<WebElement> listForm = driver.findElements(By.tagName("form"));
                    for (WebElement form : listForm) {
                        List<WebElement> listInput = form.findElements(By.tagName("input"));
                        for (WebElement input : listInput) {
                            if (input.getAttribute("value").equalsIgnoreCase(kereta)) {
                                WebElement btn = form.findElement(By.className("itButton"));
                                btn.click();
                                System.out.println("========================>KLIK BOOKING");
                                keeploop = false;
                                throw new KlikException("BerhasilKlik");
                            }
                        }
                    }
                }
                System.out.println("==========================> looping ke: " + counter);
                counter++;
            } catch (KlikException ke) {
                System.out.println("================> Masuk Klik Exception");
                keeploop = false;
                break;
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("===================> Reconecting..." + link.getValue());
                driver.get(link.getValue());
            }
        }

        //       System.out.println("ada keretaaaaaa: "+list.size());
        List<WebElement> listInput = driver.findElements(By.tagName("input"));
        for (WebElement input : listInput) {
            if (input.getAttribute("type").equals("checkbox")) {
                input.click();
                break;
            }
        }
        WebElement lanjut = driver.findElement(By.cssSelector("input[type='submit'][name='booking']"));
        lanjut.click();

        //Ngisi Tikete 
        //Nunggu disit
        //tunggu sampe page ready, nandainnya kalo element div dengan css class "txt_first_name_adult_1" muncul
        WebElement elementForWait = (new WebDriverWait(driver, 3))
                .until(ExpectedConditions.visibilityOfElementLocated(By.id("txt_first_name_adult_1")));
        //end wait
        WebElement namaPenumpang = driver.findElement(By.id("txt_first_name_adult_1"));
        WebElement ktp = driver.findElement(By.id("txt_passport_1"));

        WebElement contactName = driver.findElement(By.id("txt_contact_first_name"));
        WebElement contactEmail = driver.findElement(By.id("txt_contact_email"));
        WebElement contactPhone = driver.findElement(By.id("txt_contact_phone"));
        WebElement contactAddress = driver.findElement(By.id("txt_contact_home_address"));

        namaPenumpang.sendKeys(txtNamaPenumpang.getText());
        ktp.sendKeys(txtNoKTP.getText());
        contactName.sendKeys(txtNamaPenumpang.getText());
        contactEmail.sendKeys(txtEmail.getText());
        contactPhone.sendKeys(txtNoTelp.getText());
        contactAddress.sendKeys(txtAlamat.getText());

        playSound();

        JOptionPane.showMessageDialog(rootPane,
                "Booking sudah tersedia, Silakan inputkan Captcha!! Dan lanjutkan secara manual", "Informasi",
                JOptionPane.INFORMATION_MESSAGE);
        this.setAlwaysOnTop(true);

        System.out.println("DONE");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.artnaseef.webapp.test.SimpleTest.java

License:Apache License

@Test
public void testSimple() throws Exception {
    this.driver.get(this.serverUrl + "index.html");

    String whoToSend = "foo";

    WebElement who = this.driver.findElement(By.id("who"));
    who.sendKeys(whoToSend);

    WebElement sendBtn = this.driver.findElement(By.id("send-btn"));
    sendBtn.click();/*from   w w w . ja v a  2 s .com*/

    // wait 5 secs for ajax response
    new WebDriverWait(this.driver, 5)
            .until(ExpectedConditions.textToBePresentInElement(By.id("response"), whoToSend));

    WebElement response = this.driver.findElement(By.id("response"));
    String text = response.getText();

    Assert.assertEquals("Hello " + whoToSend, text);

}

From source file:com.atomicleopard.webelemental.Element.java

License:Open Source License

public Element val(CharSequence value) {
    for (WebElement element : elements) {
        element.clear();//from   ww w.  j  a  v a  2  s  . com
        element.sendKeys(value);
    }
    return this;
}

From source file:com.atomicleopard.webelemental.Element.java

License:Open Source License

public Element text(CharSequence value) {
    for (WebElement element : elements) {
        element.clear();//from w ww .j  av  a  2  s .c o  m
        element.sendKeys(value);
    }
    return this;
}

From source file:com.autocognite.selenium.lib.SeleniumWebUiDriver.java

License:Apache License

public void focus(WebElement wdElement) throws Exception {
    wdElement.sendKeys("");
}

From source file:com.autocognite.selenium.lib.SeleniumWebUiDriver.java

License:Apache License

public void click(WebElement wdElement) throws Exception {
    waitForElementClickability(wdElement);
    try {/*w ww.  j a va  2 s .c om*/
        wdElement.click();
    } catch (Exception f) {
        focus(wdElement);
        wdElement.sendKeys(Keys.ENTER);
    }
}

From source file:com.autocognite.selenium.lib.SeleniumWebUiDriver.java

License:Apache License

public void enterText(WebElement wdElement, String value) throws Exception {
    waitForElementClickability(wdElement);
    wdElement.click();/*from   www.j  a  va  2 s .co  m*/
    wdElement.sendKeys(value);
}