Example usage for org.openqa.selenium By name

List of usage examples for org.openqa.selenium By name

Introduction

In this page you can find the example usage for org.openqa.selenium By name.

Prototype

public static By name(String name) 

Source Link

Usage

From source file:CarStoreWebSiteTest.java

@Test
public void testSearchWithMultipleFilterOR() {

    String color = "silver";
    String price = "18000.00";

    driver.findElement(By.linkText("Search")).click();
    driver.findElement(By.name("color")).sendKeys(color);
    driver.findElement(By.name("price")).sendKeys(price);
    Select dropdown = new Select(driver.findElement(By.name("price_logical")));
    dropdown.selectByValue(" OR ");
    driver.findElement(By.name("search_button")).click();

    String newPage = driver.getPageSource();
    System.out.println(newPage);//from  www .  ja v a 2  s  .  c  om

    String correct_value;
    correct_value = "ABC0006";
    assertTrue(newPage.contains(correct_value));
    correct_value = "ABC0007";
    assertTrue(newPage.contains(correct_value));
}

From source file:CarStoreWebSiteTest.java

@Test
public void testChooseCar() {
    driver.findElement(By.linkText("Search")).click();
    driver.findElement(By.name("search_button")).click();
    driver.findElement(By.name("view_car_button")).click();

    String correct_value = "The car's photo is merely illustrative, it doesn't reflect the product.";
    String newPage = driver.getPageSource();

    assertTrue(newPage.contains(correct_value));

}

From source file:IdNameDemo.java

public static void main(String[] args) {
    String baseURL = "http://www.google.com";
    System.setProperty("webdriver.gecko.driver",
            "/Users/srijana/Documents/seleniumpractise notes/geckodriver 2");
    WebDriver driver = new FirefoxDriver();

    driver.get(baseURL);/*from   w  ww  . j a v  a2s  . c  om*/

    driver.findElement(By.id("lst-ib")).sendKeys("letskodeit");
    driver.findElement(By.name("btnG")).click();
}

From source file:$.BaseSeleniumTestCase.java

License:Apache License

/**
     * ?, .//  www.ja  v a 2s. c  o  m
     */
    protected static void loginAsUserIfNecessary() {
        s.open("/task");

        if (s.getTitle().contains("")) {
            s.type(By.name("username"), "user");
            s.type(By.name("password"), "user");
            s.check(By.name("rememberMe"));
            s.click(By.id("submit_btn"));
            s.waitForTitleContains("?");
        }
    }

From source file:$.RegisterFT.java

License:Apache License

@Test
    public void register() {
        // /*  w  ww  . j ava2s .c  o m*/
        s.open("/logout");
        s.click(By.linkText(""));

        s.type(By.id("loginName"), "user2");
        s.type(By.id("name"), "Kevin");
        s.type(By.id("plainPassword"), "user2");
        s.type(By.id("confirmPassword"), "user2");

        s.click(By.id("submit_btn"));

        // 
        s.waitForTitleContains("");
        assertThat(s.getValue(By.name("username"))).isEqualTo("user2");

        s.type(By.name("password"), "user2");
        s.click(By.id("submit_btn"));

        // ?
        s.waitForTitleContains("?");

        // 
        s.open("/logout");
    }

From source file:$.SecurityFT.java

License:Apache License

/**
     * ???./*from  w w  w .j  a  v  a 2  s. c  o  m*/
     */
    @Test
    public void loginWithWrongPassword() {
        s.open("/logout");
        s.type(By.name("username"), "wrongUser");
        s.type(By.name("password"), "WrongPassword");
        s.check(By.name("rememberMe"));
        s.click(By.id("submit_btn"));

        s.waitForTitleContains("");
        assertThat(s.isTextPresent("?.")).isTrue();
    }

From source file:$.TaskGuiFT.java

License:Apache License

/**
     * //?/./*from w w w.j  a v  a  2  s  . co  m*/
     */
    @Test
    @Category(Smoke.class)
    public void crudTask() {
        s.open("/task/");

        // create
        s.click(By.linkText(""));

        Task task = TaskData.randomTask();
        s.type(By.id("task_title"), task.getTitle());
        s.click(By.id("submit_btn"));

        assertThat(s.isTextPresent("?")).isTrue();

        // update
        s.click(By.linkText(task.getTitle()));
        assertThat(s.getValue(By.id("task_title"))).isEqualTo(task.getTitle());

        String newTitle = TaskData.randomTitle();
        s.type(By.id("task_title"), newTitle);
        s.click(By.id("submit_btn"));
        assertThat(s.isTextPresent("?")).isTrue();

        // search
        s.type(By.name("search_LIKE_title"), newTitle);
        s.click(By.id("search_btn"));
        assertThat(s.getTable(By.id("contentTable"), 0, 0)).isEqualTo(newTitle);

        // delete
        s.click(By.linkText(""));
        assertThat(s.isTextPresent("?")).as("??").isTrue();
    }

From source file:$.UserAdminFT.java

License:Apache License

@BeforeClass
    public static void loginAsAdmin() {
        s.open("/logout");
        s.type(By.name("username"), "admin");
        s.type(By.name("password"), "admin");
        s.click(By.id("submit_btn"));
    }/*ww w  .  ja  v  a 2s . com*/

From source file:alwaysonline.Access.java

License:Open Source License

/**
 * Method for the access.// w ww .j a v  a 2s .  c o  m
 * @param user String that contains the username
 * @param pass String that contains the password
 * @return Access result: 0 failed, 1 success.
 */
public int doAccess(String user, String pass) {
    WebDriver driver = new HtmlUnitDriver();
    WebElement username, password;

    // access page
    driver.get("https://auth3.unipi.it/auth/perfigo_cm_validate.jsp");
    // looking for the credential fields
    username = driver.findElement(By.name("username"));
    username.clear();
    username.sendKeys(user);
    password = driver.findElement(By.name("password"));
    password.clear();
    password.sendKeys(pass);
    // Executing the access, submiting values
    driver.findElement(By.name("username")).submit();
    // If the session was already opened
    if (driver.getPageSource().contains("Too many users using this account")) {
        // put again credentials
        username = driver.findElement(By.name("username"));
        username.clear();
        username.sendKeys(user);
        password = driver.findElement(By.name("password"));
        password.clear();
        password.sendKeys(pass);
        // remove the old session
        driver.findElement(By.name("remove_old")).click();
        // submit again access data
        driver.findElement(By.name("username")).submit();
    }
    // controll if the access has been done successful
    if (driver.getPageSource().contains("You have been successfully logged on the network"))
        return 1;
    return 0;
}

From source file:app.Stepdefs.java

@Given("^searchdata \"([^\"]*)\" is given$")
public void searchdata_is_given(String searchData) throws Throwable {
    driver.findElement(By.name("search")).sendKeys(searchData);
}