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:bst.cpo.automation.dm.actions.SystemOverview_Actions.java

public void Set_User(String strUser) {
    //<input type="text" ng-model="pp.query" maxlength="60" required="" class="ng-dirty ng-invalid ng-invalid-required">
    WebElement element = DMDriver
            .findElement(By.xpath("//*[@id='app']/div/div[4]/div/div/div[2]/div[1]/div[1]/form/input[1]"));
    element.click();/*w w w  . j ava 2 s .  c  o  m*/
    element.clear();
    element.sendKeys(strUser);
}

From source file:ca.nrc.cadc.search.integration.AbstractSearchFormPage.java

License:Open Source License

void enterInputValue(final WebElement inputElement, final String value) throws Exception {
    final String inputID = inputElement.getAttribute("id");

    summonTooltip(inputID);//from  w  w  w . j a v  a 2s  .  c o  m
    showInputField(inputID);
    waitForElementVisible(inputElement);

    for (int i = 0; i < value.length(); i++) {
        inputElement.sendKeys(Character.toString(value.charAt(i)));
        waitFor(150L);
    }

    closeTooltip();
}

From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java

License:Open Source License

protected void inputTextValue(final By by, final String value, final boolean clean, final boolean moveToInput)
        throws Exception {
    waitForElementPresent(by);//www.  j  ava 2s.  co m
    final WebElement inputElement = find(by);

    if (moveToInput) {
        hover(by);
        inputElement.click();
    }

    if (clean) {
        clearTextInput(by);
    }

    if (StringUtil.hasText(value)) {
        for (final char c : value.toCharArray()) {
            inputElement.sendKeys(Character.toString(c));
            waitFor(250L);
        }
    }
}

From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java

License:Open Source License

public void sendKeys(final WebElement webElement, final String value) throws Exception {
    webElement.clear();/*from   w w  w  .ja va  2s  . com*/
    webElement.sendKeys(Keys.BACK_SPACE);
    webElement.sendKeys(value);
}

From source file:CartTest.CartTest.java

@Test
public void changeQuantity() {

    this.addItemIntoCart();

    WebElement itemQuantity = driver.findElement(
            By.xpath("//*[@id=\"checkout_page_container\"]/div[1]/table/tbody/tr[2]/td[3]/form/input[1]"));
    itemQuantity.clear();//clear the quantity input bar
    itemQuantity.sendKeys("10");//change the quantity into 10
    driver.findElement(//from  w  w w. jav  a 2 s. c om
            By.xpath("//*[@id=\"checkout_page_container\"]/div[1]/table/tbody/tr[2]/td[3]/form/input[4]"))
            .click();//press "change" button
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);// wait
    assertEquals(driver
            .findElement(
                    By.xpath("//*[@id=\"checkout_page_container\"]/div[1]/table/tbody/tr[2]/td[5]/span/span"))
            .getText(), "$120.00");// the total price should become to "120"

}

From source file:cc.kune.selenium.KuneSeleniumDefaults.java

License:GNU Affero Public License

/**
 * Send keys but in a slow way (word by word).
 * /*from   www .jav  a2 s  . c  o  m*/
 * @param element
 *          the element
 * @param strings
 *          the strings
 */
public void sendKeys(final WebElement element, final String... strings) {
    for (final String s : strings) {
        final String[] splitted = s.split(" ");
        for (int i = 0; i < splitted.length; i++) {
            element.sendKeys(splitted[i]);
            if (i < splitted.length - 1) {
                element.sendKeys(" ");
            }
        }
    }
}

From source file:ccnu.computer.crawler.WeiboCN.java

/**
 * ??cookieweibo.cnweibo.com weibo.cn?????
 *
 * @param username ???//from  w w  w .j a  va 2s.co  m
 * @param password ??
 * @return
 * @throws Exception
 */
public static String getSinaCookie(String username, String password) throws Exception {
    StringBuilder sb = new StringBuilder();
    HtmlUnitDriver driver = new HtmlUnitDriver();
    driver.setJavascriptEnabled(true);
    driver.get("http://login.weibo.cn/login/");
    WebElement ele = driver.findElementByCssSelector("img");
    String src = ele.getAttribute("src");
    String cookie = concatCookie(driver);
    HttpRequest request = new HttpRequest(src);
    request.setCookie(cookie);
    HttpResponse response = request.getResponse();
    ByteArrayInputStream is = new ByteArrayInputStream(response.getContent());
    BufferedImage img = ImageIO.read(is);
    is.close();
    ImageIO.write(img, "png", new File("result.png"));
    String userInput = new CaptchaFrame(img).getUserInput();
    WebElement mobile = driver.findElementByCssSelector("input[name=mobile]");
    mobile.sendKeys(username);
    WebElement pass = driver.findElementByCssSelector("input[name^=password]");
    pass.sendKeys(password);
    WebElement code = driver.findElementByCssSelector("input[name=code]");
    code.sendKeys(userInput);
    WebElement rem = driver.findElementByCssSelector("input[name=remember]");
    rem.click();
    WebElement submit = driver.findElementByCssSelector("input[name=submit]");
    submit.click();
    String result = concatCookie(driver);
    driver.close();
    if (result.contains("gsid_CTandWM")) {
        return result;
    } else {
        throw new Exception("weibo login failed");
    }
}

From source file:ch.vorburger.webdriver.reporting.tests.SampleGoogleSearchReportTest.java

License:Apache License

@Test
public void testGoogleSearch() {
    EventFiringWebDriver driverWithReporting;
    {/*from w  ww  . j ava  2s.c om*/
        // System.setProperty("webdriver.chrome.driver", "/opt/google/chrome/chrome");
        // WebDriver driver = new ChromeDriver();
        WebDriver driver = new FirefoxDriver();

        WebDriverEventListener loggingListener = new LoggingWebDriverEventListener(LOG_FILE_WRITER);
        ;
        driverWithReporting = new EventFiringWebDriver(driver);
        driverWithReporting.register(loggingListener);
    }

    driverWithReporting.get("http://www.google.com");
    WebElement element = driverWithReporting.findElement(By.name("q"));
    element.sendKeys("Mifos");
    element.submit();

    (new WebDriverWait(driverWithReporting, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.id("bfoot")));

    driverWithReporting.quit();
}

From source file:chromedriveryahoologin.ChromeDriverDeleteTrashEmails.java

public static void main(String[] args) {
    try {/*from   w  w w  .  j  a v a  2  s .  c  o m*/

        Integer pozSpam = 0;
        Integer pozTrash = 0;
        Integer pozHelp = 0;
        Integer pozCompose = 0;
        Integer pozNewFolder = 0;

        System.setProperty("webdriver.chrome.driver",
                "D:\\Proiecte\\selenium-java-2.47.1\\selenium-2.47.1\\chromedriver_win32\\chromedriver.exe");
        System.setProperty("webdriver.chrome.logfile",
                "D:\\prjAutJava\\YahooLogin\\ChromeDriverDeleteSpam.log");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("test-type");
        options.addArguments("--start-maximized");
        options.addArguments("--disable-web-security");
        options.addArguments("--no-proxy-server");
        options.addArguments("--disable-extensions");
        options.addArguments("--disable-notifications");
        options.addArguments("--disable-popup-blocking");
        options.addArguments("--disable-plug-in");
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("credentials_enable_service", false);
        prefs.put("profile.password_manager_enabled", false);

        options.setExperimentalOption("prefs", prefs);

        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        capabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true);
        capabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);
        capabilities.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true);
        capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
        capabilities.setCapability(CapabilityType.PLATFORM, "WIN10");

        driver = new ChromeDriver(capabilities);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("https://mail.yahoo.com");
        driver.manage().window().maximize();
        WebElement usernameElem = driver.findElement(By.id("login-username"));
        usernameElem.sendKeys("andadeacu@yahoo.com");

        WebElement Next = driver.findElement(By.name("signin"));
        Next.click();

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        WebElement passwordElem = driver.findElement(By.xpath("//input[@id='login-passwd']"));
        boolean selected = passwordElem.isSelected();

        CharSequence password = "";
        passwordElem.sendKeys(password);

        WebElement login = driver.findElement(By.id("login-signin"));

        login.click();
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        driver.switchTo().activeElement();

        WebElement tooltipElem = driver.findElement(By.xpath("//div[@class='Pos(r) M(0) TooltipContent']"));

        List<WebElement> childs = tooltipElem.findElements(By.xpath("//ul/li"));

        for (int j = 0; j < childs.size(); j++) {

            WebElement spamElem = childs.get(j);
            /*
            * System.out.println("ancorele " + j + " " + " tag " +
            * childs.get(j).getTagName() + " " + childs.get(j).getText() +
            * " " + childs.get(j).getAttribute("innerHTML"));
             */
            if (spamElem.getText().startsWith(("Spam"))) {

                pozSpam = j;

            }
            if (spamElem.getText().startsWith(("Help"))) {

                pozHelp = j;

            }
            if (spamElem.getText().startsWith(("Compose"))) {

                pozCompose = j;

            }
            if (spamElem.getText().startsWith(("New"))) {

                pozNewFolder = j;

            }

            if (spamElem.getText().startsWith(("Trash"))) {
                System.out.println(j + " Trash is " + spamElem.getTagName() + " " + spamElem.getText());
                pozTrash = j;
                break;
            }

        }
        System.out.println(pozTrash);

        WebElement trashElem = childs.get(pozTrash);

        /*
        * System.out.println("trashElem " + trashElem.getTagName() +
        * " text " + trashElem.getText() + " class_atribute " +
        * trashElem.getAttribute("class") + " data_action " +
        * trashElem.getAttribute("data_action"));
         */
        WebElement trashFolderEmpty = trashElem.findElement(
                By.xpath("//a[@class='x-gap btn btn-trash']/span/span[@class='btn icon  icon-delete']"));

        /*
        * System.out.println("spamEmptyFolder " +
        * spamFolderEmpty.getTagName() + " text " +
        * spamFolderEmpty.getText() + " location " +
        * spamFolderEmpty.isEnabled());
         */
        trashFolderEmpty.click();

        int timeOut = 5;

        WebDriverWait wait = new WebDriverWait(driver, timeOut);

        driver.switchTo().alert();

        /* for Chrome is not working 
        WebElement modalPopUp = driver.findElement(By
            .className("modal-hd yui3-widget-hd"));
                
        */

        WebElement btnDeleteSpamEmails = driver.findElement(By.className("btn left right default"));

        /*
        * <button id="okayModalOverlay" class="btn left right default"
        * title="OK" role="button" data-action="ok">OK</button>
         */
        btnDeleteSpamEmails.click();

        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        driver.switchTo().activeElement();

        // verify msg after you delete spam emails
        System.out.println(driver.getCurrentUrl());

        driver.quit();
    } catch (Exception ex) {

        ex.printStackTrace();
        driver.quit();
    }

}

From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

public void enterDealerName(String dealerNameString) throws Throwable {
    WebElement dealerName = driver.findElement(By.xpath(
            "/html/body/div/div[1]/div[1]/div[2]/div[1]/div/div/div/form/fieldset/div[1]/div[2]/div[1]/div[1]/div/input"));
    dealerName.clear();//from   w w  w.  ja  v  a2s  .  co  m
    dealerName.sendKeys(dealerNameString);
}