Example usage for org.openqa.selenium By id

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

Introduction

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

Prototype

public static By id(String id) 

Source Link

Usage

From source file:$.TaskGuiFT.java

License:Apache License

/**
     * ?.//from w ww  .ja va 2s .  co  m
     */
    @Test
    @Category(Smoke.class)
    public void viewTaskList() {
        s.open("/task/");
        WebElement table = s.findElement(By.id("contentTable"));
        assertThat(s.getTable(table, 0, 0)).isEqualTo("Release SpringSide 4.0");
    }

From source file:$.TaskGuiFT.java

License:Apache License

/**
     * //?/./*from   w  w  w  . j  a  va 2  s. c om*/
     */
    @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:$.TaskGuiFT.java

License:Apache License

@Test
    public void inputInValidateValue() {
        s.open("/task/");
        s.click(By.linkText(""));
        s.click(By.id("submit_btn"));

        assertThat(s.getText(By.xpath("//fieldset/div/div/span"))).isEqualTo("");
    }//from   w  w  w  . ja v a  2  s.  c  om

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"));
    }/*from ww  w.  ja  v  a  2s .  c om*/

From source file:$.UserAdminFT.java

License:Apache License

/**
     * ?./*  ww  w .j  ava 2  s.  com*/
     */
    @Test
    @Category(Smoke.class)
    public void viewUserList() {
        s.open("/admin/user");
        WebElement table = s.findElement(By.id("contentTable"));
        assertThat(s.getTable(table, 0, 0)).isEqualTo("admin");
        assertThat(s.getTable(table, 1, 0)).isEqualTo("user");
    }

From source file:$.UserAdminFT.java

License:Apache License

@Test
    public void editUser() {
        s.open("/admin/user/update/2");
        s.type(By.id("name"), "Kevin");
        s.type(By.id("plainPassword"), "user2");
        s.type(By.id("confirmPassword"), "user2");
        s.click(By.id("submit_btn"));

        assertThat(s.isTextPresent("user?")).as("??").isTrue();
        WebElement table = s.findElement(By.id("contentTable"));
        assertThat(s.getTable(table, 1, 1)).isEqualTo("Kevin");
    }/*from   ww  w.  j a v  a  2s.  com*/

From source file:administrationedit.addCompany.java

public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
    driver = new ChromeDriver();
    WebDriverWait wait = new WebDriverWait(driver, 3);
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    Random r = new Random();

    Faker faker = new Faker();

    driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/user/updateCompanySettings");

    adminLogin login = new adminLogin(driver);
    login.loginToAdmin("demo", "demo");

    // Input name
    String nameComp = faker.company().name();
    driver.findElement(By.id("name")).clear();
    driver.findElement(By.id("name")).sendKeys(nameComp);

    // Input address
    String addressComp = faker.address().fullAddress();
    driver.findElement(By.id("address")).clear();
    driver.findElement(By.id("address")).sendKeys(addressComp);

    // Input city
    String cityComp = faker.address().city();
    driver.findElement(By.id("city")).clear();
    driver.findElement(By.id("city")).sendKeys(cityComp);

    // Input postal code
    String postalCodeComp = faker.address().zipCode();
    driver.findElement(By.id("postalCode")).clear();
    driver.findElement(By.id("postalCode")).sendKeys(postalCodeComp);

    // Country//from   w  w w .  ja va 2  s  .c o m
    Select countryComp = new Select(driver.findElement(By.id("country")));
    int coutryCompInt = r.nextInt(countryComp.getOptions().size()) + 1;
    countryComp.selectByIndex(coutryCompInt);

    // Email
    String emailComp = faker.internet().emailAddress();
    driver.findElement(By.id("email")).clear();
    driver.findElement(By.id("email")).sendKeys(emailComp);

    // Phone
    String phoneComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", "");
    driver.findElement(By.id("phone")).clear();
    driver.findElement(By.id("phone")).sendKeys(phoneComp);

    // Mobile
    String mobileComp = faker.phoneNumber().cellPhone().replaceAll("\\D", "");
    driver.findElement(By.id("mobilePhone")).clear();
    driver.findElement(By.id("mobilePhone")).sendKeys(mobileComp);

    // Fax
    String faxComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", "");
    driver.findElement(By.id("fax")).clear();
    driver.findElement(By.id("fax")).sendKeys(faxComp);

    // OIB
    String oibComp = faker.idNumber().validSvSeSsn();
    driver.findElement(By.id("oib")).clear();
    driver.findElement(By.id("oib")).sendKeys(oibComp);

    // VatID
    String vatComp = faker.idNumber().validSvSeSsn();
    driver.findElement(By.id("vatId")).clear();
    driver.findElement(By.id("vatId")).sendKeys(vatComp);

    // Id code
    String idCodeComp = faker.idNumber().valid();
    driver.findElement(By.id("idCode")).clear();
    driver.findElement(By.id("idCode")).sendKeys(idCodeComp);

    // MBS
    String mbsComp = faker.number().digits(15);
    driver.findElement(By.id("mbs")).clear();
    driver.findElement(By.id("mbs")).sendKeys(mbsComp);

    // ID number
    String idNumComp = faker.number().digits(15);
    driver.findElement(By.id("identificationNumber")).clear();
    driver.findElement(By.id("identificationNumber")).sendKeys(idNumComp);

    // IBAN
    String ibanComp = faker.finance().iban();
    driver.findElement(By.id("iban")).clear();
    driver.findElement(By.id("iban")).sendKeys(ibanComp);

    // Swift 
    String swiftComp = faker.finance().bic();
    driver.findElement(By.id("swift")).clear();
    driver.findElement(By.id("swift")).sendKeys(swiftComp);

    //Bank name
    String bankNameComp = faker.name().name();
    driver.findElement(By.id("bankName")).clear();
    driver.findElement(By.id("bankName")).sendKeys(bankNameComp);

    // Bank address
    String bankAddressComp = faker.address().fullAddress();
    driver.findElement(By.id("bankAddress")).clear();
    driver.findElement(By.id("bankAddress")).sendKeys(bankAddressComp);

    // Bank city
    String bankCityComp = faker.address().city();
    driver.findElement(By.id("bankCity")).clear();
    driver.findElement(By.id("bankCity")).sendKeys(bankCityComp);

    // Bank postal code
    String bankPostalCodeComp = faker.address().zipCode();
    driver.findElement(By.id("bankPostalCode")).clear();
    driver.findElement(By.id("bankPostalCode")).sendKeys(bankPostalCodeComp);

    // Bank country
    Select bankCountryComp = new Select(driver.findElement(By.id("bankCountry")));
    int bankCoutryCompInt = r.nextInt(bankCountryComp.getOptions().size()) + 1;
    bankCountryComp.selectByIndex(bankCoutryCompInt);

    // Social 
    String socialTW = faker.internet().url();
    String socialFB = faker.internet().url();
    driver.findElement(By.id("twitterUsername")).clear();
    driver.findElement(By.id("facebookID")).clear();
    driver.findElement(By.id("twitterUsername")).sendKeys(socialTW);
    driver.findElement(By.id("facebookID")).sendKeys(socialFB);

    // SAVE
    driver.findElement(
            By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[26]/div/button"))
            .click();

}

From source file:administrationedit.addOffice.java

public static void main(String[] args) throws InterruptedException {

    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
    driver = new ChromeDriver();
    WebDriverWait wait = new WebDriverWait(driver, 3);
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    String[] city = { "Rijeka", "Pula", "Pore?", "Rovinj", "Umag", "Novigrad", "Vrsar", "Pazin", "Motovun",
            "Medulin", "Faana", "Vodnjan", "Opatija", "Krk", "Punat", "Baka", "Njivice", "Labin", "Rabac",
            "Plomin", "I?ii", "Ika", "Malinska", "Njivice", "Omialj", "Dramalj", "Crikvenica", "Selce",
            "Cres", "Rab", "Novi Vinodolski", "Povile", "iii", "Vodice", "Pinezii", "Lovran", "Medveja",
            "shanghai", "sao paulo", "kinshasa", "cairo", "peking", "london", "bogota", "dhaka",
            "rio de janeiro", "santiago", "toronto", "sydney", "wuhan", "chongqing", "xian", "chengdu",
            "alexandria", "tianjin", "melbourne", "abidjan", "shenyang", "berlin", "montreal", "harbin",
            "guangzhou", "madrid", "nanjing", "kabul", "luanda", "addis abeba", "taiyuan", "salvador",
            "changchun", "gizeh", "fortaleza", "cali", "belo horizonte", "brasilia", "santo domingo", "paris",
            "jinan", "tangshan", "dalian", "medellin", "algiers", "accra", "guayaquil", "jilin", "hangzhou",
            "nanchang", "conakry", "brisbane", "vancouver", "minsk", "hamburg", "curitiba", "qingdao", "manaus",
            "xinyang", "barcelona", "vienna", "urumqi", "recife", "kumasi", "perth", "cordoba", "lanzhou",
            "belem", "fushun", "quito", "luoyang", "hefei", "barranquilla", "lubumbashi", "porto alegre",
            "handan", "suzhou", "khulna", "douala", "yaounde", "munich", "rosario", "anshan", "xuzhou",
            "fuzhou", "guiyang", "goiania", "guarulhos", "prague", "dubai", "baku", "brazzaville", "wuxi",
            "yerevan", "copenhagen", "adelaide", "sofia", "datong", "tbilisi", "xianyang", "campinas",
            "ouagadougou", "huainan", "kunming", "brussels", "shenzhen", "nova iguacu", "rongcheng", "baoding",
            "benxi", "birmingham", "mendoza", "cologne", "calgary", "maceio", "cartagena", "changzhou",
            "sao goncalo", "sao luis", "huaibei", "cochabamba", "pingdingshan", "qiqihar", "mbuji-mayi",
            "ottawa", "wenzhou", "tucuman", "edmonton", "duque de caxias", "la paz", "nanning", "marseille",
            "anyang", "hohhot", "valencia", "xining", "liuzhou", "natal", "qinhuangdao", "hengyang", "taian",
            "teresina", "xinxiang", "sao bernardo do campo", "hegang", "campo grande", "athens", "cucuta",
            "langfang", "ningbo", "yantai", "zhuzhou", "jaboatao", "rajshahi", "sarajevo", "zhangjiakou",
            "cotonou", "zigong", "fuxin", "liaoyang", "sevilla", "la plata", "bangui", "osasco", "zhangdian",
            "puyang", "nantong", "mudanjiang", "santo andre", "hamilton", "joao pessoa", "shaoyang", "guilin",
            "frankfurt", "wahran", "mar del plata", "quebec", "zhanjiang", "zaragoza", "zhenjiang", "winnipeg",
            "dandong", "shaoguan", "yancheng", "foshan", "contagem", "jibuti", "haikou", "sao jose dos campos",
            "taizhou", "xingtai", "glasgow", "jinzhou", "abu dhabi", "luancheng", "dortmund", "stuttgart",
            "yingkou", "zhangzhou", "belfast" };

    Random r = new Random();

    Faker faker = new Faker();

    driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/office/add");

    adminLogin login = new adminLogin(driver);
    login.loginToAdmin("demo", "demo");

    // Input name
    String nameComp = faker.company().name();
    driver.findElement(By.id("name")).clear();
    driver.findElement(By.id("name")).sendKeys(nameComp);

    // Input address
    String addressComp = faker.address().fullAddress();
    driver.findElement(By.id("address")).clear();
    driver.findElement(By.id("address")).sendKeys(addressComp);

    // Input city
    String cityComp = faker.address().city();
    driver.findElement(By.id("city")).clear();
    driver.findElement(By.id("city")).sendKeys(cityComp);

    // Input postal code
    String postalCodeComp = faker.address().zipCode();
    driver.findElement(By.id("postalCode")).clear();
    driver.findElement(By.id("postalCode")).sendKeys(postalCodeComp);

    // Country//w  ww .jav a2  s .  c o  m
    Select countryComp = new Select(driver.findElement(By.id("country")));
    int coutryCompInt = r.nextInt(countryComp.getOptions().size()) + 1;
    countryComp.selectByIndex(coutryCompInt);

    // Email
    String emailComp = faker.internet().emailAddress();
    driver.findElement(By.id("email")).clear();
    driver.findElement(By.id("email")).sendKeys(emailComp);

    // Phone
    String phoneComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", "");
    driver.findElement(By.id("phone")).clear();
    driver.findElement(By.id("phone")).sendKeys(phoneComp);

    // Mobile
    String mobileComp = faker.phoneNumber().cellPhone().replaceAll("\\D", "");
    driver.findElement(By.id("mobilePhone")).clear();
    driver.findElement(By.id("mobilePhone")).sendKeys(mobileComp);

    // Fax
    String faxComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", "");
    driver.findElement(By.id("fax")).clear();
    driver.findElement(By.id("fax")).sendKeys(faxComp);

    // Geolocation
    int cityN = r.nextInt(city.length);
    driver.findElement(By
            .xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[10]/div[1]/div[1]/input"))
            .sendKeys(city[cityN]);
    driver.findElement(
            By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[10]/div[1]/div[1]/a"))
            .click();
    Thread.sleep(3000);
    // SAVE
    driver.findElement(
            By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[12]/div/button"))
            .click();

}

From source file:administrationedit.setSeasonTemplate.java

public static void main(String[] args) throws InterruptedException {

    for (int y = 0; y < 2; y++) {

        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
        driver = new ChromeDriver();
        WebDriverWait wait = new WebDriverWait(driver, 3);
        driver.manage().window().maximize();

        Random r = new Random();

        Faker faker = new Faker();

        driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/accommodation/seasonTemplateAdd");

        adminLogin login = new adminLogin(driver);
        login.loginToAdmin("demo", "demo");

        int currentYear = Calendar.getInstance().get(Calendar.YEAR) + y;
        String curYear = String.valueOf(currentYear);

        // Input name of template
        driver.findElement(By.id("name")).sendKeys("Season-" + curYear);

        // Choose year
        Select year = new Select(driver.findElement(By.id("year")));
        year.selectByVisibleText(curYear);

        // Now select seasons
        WebElement tableId = driver.findElement(By.xpath("//*[@class='ui-calendar hasDatepicker']"));
        if (year.getFirstSelectedOption().getText().equals(curYear)) {
            String id = tableId.getAttribute("id");

            for (int i = 1; i <= 12; i++) {
                Thread.sleep(1000);
                for (int j = 1; j <= 7; j++) {
                    if (!driver.findElements(By.xpath(
                            "//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[1]/td[" + j + "]/a"))
                            .isEmpty()) {
                        driver.findElement(By.xpath(
                                "//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[1]/td[" + j + "]/a"))
                                .click();
                        break;
                    }//  w w  w  . ja  v  a2  s . c  om
                }
                i++;
                int weeks = driver
                        .findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr"))
                        .size();

                int test = 0;
                for (int j = 7; j >= 1; j--) {
                    if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr["
                            + weeks + "]/td[" + j + "]/a")).isEmpty()) {
                        test = 1;
                        break;
                    } else
                        test = 2;
                }
                switch (test) {
                case 1:
                    for (int j = 7; j >= 1; j--) {
                        if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i
                                + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).isEmpty()) {
                            driver.findElement(By.xpath("//*[@id='" + id + "']/div/div[" + i
                                    + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).click();
                            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select")));
                            Select season1 = new Select(driver.findElement(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select")));
                            int season1int = r.nextInt(season1.getOptions().size() - 1) + 1;
                            season1.selectByIndex(season1int);
                            driver.findElement(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[4]/div/a[2]"))
                                    .click();
                            break;
                        }
                    }
                    break;
                case 2:
                    for (int j = 7; j >= 1; j--) {
                        if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i
                                + "]/table/tbody/tr[" + (weeks - 1) + "]/td[" + j + "]/a")).isEmpty()) {
                            driver.findElement(By.xpath("//*[@id='" + id + "']/div/div[" + i
                                    + "]/table/tbody/tr[" + (weeks - 1) + "]/td[" + j + "]/a")).click();
                            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select")));
                            Select season2 = new Select(driver.findElement(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select")));
                            int season2int = r.nextInt(season2.getOptions().size() - 1) + 1;
                            season2.selectByIndex(season2int);
                            driver.findElement(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[4]/div/a[2]"))
                                    .click();
                            break;
                        }
                    }
                }
            }
        }

        // SAVE
        wait.until(ExpectedConditions.visibilityOfElementLocated(
                By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[3]/div/input")));
        driver.findElement(By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[3]/div/input"))
                .click();
        if (driver.getTitle().equals("Accommodation season templates administration")) {
            driver.close();
        }
    }
}

From source file:akori.SELENIUM.java

public static void main(String[] args) throws Exception {
    // The Firefox driver supports javascript 
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();
    System.out.println(driver.manage().window().getSize().toString());
    System.out.println(driver.manage().window().getPosition().toString());
    URL = "http://www.mbauchile.cl";
    PATH = "E:\\NetBeansProjects\\AKORI\\1.png";

    // Go to the Google Suggest home page
    driver.get(URL);//  w  w  w.j a v  a  2s  .com

    // Enter the query string "Cheese"
    WebElement query = driver.findElement(By.id("container"));
    Point p = query.getLocation();
    Dimension d = query.getSize();

    System.out.println("x: " + p.x + " y: " + p.y);
    System.out.println("width: " + d.width + " height: " + d.height);

    driver.quit();
}