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.mycompany.selenium.SeleniumTests.java

@Test
public void test2() throws Exception {
    WebElement element = driver.findElement(By.id("filter"));
    element.clear();/*from w  w w. j  a v a  2 s  . co m*/
    element.sendKeys("2002");
    WebElement table = driver.findElement(By.tagName("tbody"));
    List<WebElement> rows = table.findElements(By.tagName("tr"));
    Assert.assertThat(rows.size(), is(2));
}

From source file:com.mycompany.selenium.SeleniumTests.java

@Test
public void test3() throws Exception {
    WebElement element = driver.findElement(By.id("filter"));
    element.sendKeys(Keys.BACK_SPACE);
    WebElement table = driver.findElement(By.tagName("tbody"));
    List<WebElement> rows = table.findElements(By.tagName("tr"));
    Assert.assertThat(rows.size(), is(5));
}

From source file:com.mycompany.seleniumtest.Selenium2Example.java

public static void main(String[] args) {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.

    System.setProperty("webdriver.chrome.driver", "/Users/CosticaTeodor/Downloads/drivers/chromedriver");
    System.setProperty("webdriver.safari.driver", "/usr/bin/safaridriver");

    //WebDriver driver = new ChromeDriver();
    WebDriver driver = new ChromeDriver();

    // And now use this to visit the cars program
    driver.get("http://localhost:3000/");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.google.com");

    //verify the page is loaded, wait 10 seconds if it doesn't
    try {//from  www . ja v a 2 s  .c  om
        driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
        System.out.println("Page loaded!");
    } catch (Exception e) {
        System.err.println(e.getMessage());
        System.err.println(e.getStackTrace());
    }

    int rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size();
    if (rowCount == 5) {
        System.out.println(rowCount + " is the row count!");
    } else {
        System.out.println("rowcount should be different!");
    }

    // Find the filter input element by its name
    WebElement searchFilter = driver.findElement(By.id("filter"));

    // Enter 2002 to search for
    searchFilter.sendKeys("2002");

    //check if there are two rows left
    rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size();
    System.out.println("Row count after filter is: " + rowCount);

    searchFilter.clear();
    searchFilter.sendKeys("");

    rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size();
    System.out.println("Row count after filter is: " + rowCount);
    //Close the browser
    driver.quit();
}

From source file:com.mycompany.seliniumtest.Selenium2Example.java

public static void main(String[] args) {
    System.setProperty("webdriver.gecko.driver", "/usr/local/Cellar/geckodriver/geckodriver");

    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface,
    // not the implementation.

    //WebDriver driver = new FirefoxDriver();
    //WebDriver driver = new ChromeDriver();
    WebDriver driver = new FirefoxDriver();
    //WebDriver driver = new HtmlUnitDriver();

    // And now use this to visit Google
    driver.get("http://www.google.com");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.google.com");

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();//from   ww w  .j a v  a2 s  .co  m

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());

    // Google's search is rendered dynamically with JavaScript.
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().toLowerCase().startsWith("cheese!");
        }
    });

    // Should see: "cheese! - Google Search"
    System.out.println("Page title is: " + driver.getTitle());

    //Close the browser
    driver.quit();
}

From source file:com.nabla.project.fronter.selenium.tests.GoogleSearchSTest.java

License:Open Source License

@Test
public void testGoogleSearch() {
    // try/*from   w  w w .j  a va  2 s .  co m*/
    // {

    // Find the text input element by its name
    final WebElement element = this.driver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Selenium testing tools cookbook");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();

    // Google's search is rendered dynamically with JavaScript.
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(this.driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(final WebDriver d) {
            return d.getTitle().toLowerCase().startsWith("selenium testing tools cookbook");
        }
    });

    // Should see: selenium testing tools cookbook - Google Search
    // Assert.assertEquals("Selenium testing tools cookbook - Google Search", this.driver.getTitle());
    Assert.assertEquals("Selenium testing tools cookbook - Recherche Google", this.driver.getTitle());
    /*
     * } catch (final Error e)
     * {
     * // Capture and append Exceptions/Errors
     * this.verificationErrors.append(e.toString());
     * }
     */
}

From source file:com.nexenta.qa.bs.wz.Test1Reg.java

@BeforeClass
public void setUPbro() throws MalformedURLException {
    //Get Props/*  ww w .j  av a 2 s .  c  o m*/
    Properties prop = new Properties();
    reg = new RegPanel();
    InputStream input = null;
    try {
        input = new FileInputStream(System.getProperty("propFile"));
        prop.load(input);
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    // create driver
    driver = new RemoteWebDriver(new URL("http://" + prop.getProperty("WCM") + ":4444/wd/hub"),
            DesiredCapabilities.firefox());

    driver.get("http://" + prop.getProperty("MUT") + ":8457/register/");
    String needlogin = driver.getTitle();
    logger.info(needlogin);
    if (needlogin.equals("NMV Login")) {
        WebElement nameu = driver.findElement(By.name("_nmv_username_"));
        WebElement passu = driver.findElement(By.name("_nmv_password_"));
        nameu.sendKeys("admin");
        passu.sendKeys("nexenta");
        driver.findElement(By.name("_nmv_login_")).click();
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
    }

}

From source file:com.nexenta.qa.bs.wz.Test1Reg.java

@Test
public void registerMe() {
    WebElement msig = driver.findElement(By.id(reg.MachineSigById));
    String machinesig = msig.getAttribute("value");
    //String machinesig = driver.findElement(By.id(reg.MachineSigById)).get);
    logger.info("MSIG: " + machinesig);

    try {//from   w ww.j a va 2s .com

        Process p = Runtime.getRuntime().exec(
                "/usr/bin/perl /home/user/selenium/utils/nxt-key/gen-com-key.pl " + machinesig + " TRIA 99");
        String line;
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        line = in.readLine();
        logger.info("LICENCE: " + line);
        WebElement lic = driver.findElement(By.id(reg.LicenseFieldByID));
        lic.clear();
        lic.sendKeys(line);
        in.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    driver.findElement(By.id(reg.RegisterOK)).click();
    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    assertEquals(driver.getTitle(), "Nexenta Management View: Appliance and Group Status");

}

From source file:com.nexenta.qa.bs.wz.Test3Registration.java

@Test
public void registerMe() {
    WebElement msig = driver.findElement(By.id(reg.MachineSigById));
    String machinesig = msig.getAttribute("value");
    //String machinesig = driver.findElement(By.id(reg.MachineSigById)).get);
    logger.info("MSIG: " + machinesig);

    try {/*from  w w w. j av a  2s  .c  om*/

        Process p = Runtime.getRuntime().exec(
                "perl C:\\Users\\user\\Documents\\perl\\nxt-key\\gen-com-key.pl " + machinesig + " TRIA 99");
        String line;
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        line = in.readLine();
        logger.info("LICENCE: " + line);
        WebElement lic = driver.findElement(By.id(reg.LicenseFieldByID));
        lic.clear();
        lic.sendKeys(line);
        in.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    driver.findElement(By.id(reg.RegisterOK)).click();
    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    assertEquals(driver.getTitle(), "Nexenta Management View: Appliance and Group Status");

}

From source file:com.nike.tests.MobileWebTest.java

License:Apache License

@Test
public void shouldSearchWithEbay() {
    // And now use this to visit ebay
    driver.get("http://m.ebay.de");

    System.out.println("starting flick");
    //WebElement pages = driver.findElement(By.id("vp_pages"));
    TouchActions flick = new TouchActions(driver).flick(100, 860);
    flick.perform();//from  w  w  w  . j  a  va 2  s  . co m
    TouchActions swipe = new TouchActions(driver).scroll(-200, 860);
    swipe.perform();

    TouchAction ta = (new TouchActionBuilder()).pointerDown(200, 860).pointerMove(100, 10).pointerUp().build();
    ta.perform(driver);
    System.out.println("done");
    // Find the text input element by its id
    WebElement element = driver.findElement(By.id("kw"));

    // Enter something to search for
    element.sendKeys("Nexus 5");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());
    driver.quit();
}

From source file:com.nosoftskills.travianbot.page.Login.java

License:Apache License

public void login(String userName, String password) {
    WebElement userNameElement = webDriver.findElement(By.name("name"));
    userNameElement.sendKeys(userName);
    WebElement passwordElement = webDriver.findElement(By.name("password"));
    passwordElement.sendKeys(password);/*from  ww w .  j  a  v a2s .co  m*/
    passwordElement.submit();

}