Example usage for org.openqa.selenium By tagName

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

Introduction

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

Prototype

public static By tagName(String tagName) 

Source Link

Usage

From source file:ValidSubmission.java

public static void ThenJobsTitle_ShortDesc_FullDescIs() {
    // int j =0;/*from   w  ww. j a  v a  2  s.c  o  m*/
    // Grab the table 
    WebElement table = driver.findElement(By.id("jobListings"));

    //Get number of rows in table 
    int numOfRow = table.findElements(By.tagName("tr")).size();
    List<String> jobLinkUrl = new ArrayList(numOfRow);

    for (int j = 1; j <= (numOfRow - 2); j = (j + 2)) {

        String first_part_jobShortDesc_xpath = "//*[@id='jobListings']/tbody/tr[";
        String second_part_jobShortDesc_xpath = "]/td/span";

        String first_part_jobLinkTitle_xpath = "//*[@id='jobListings']/tbody/tr[";
        String second_part_jobLinkTitle_xpath = "]/td/a";

        String first_part_jobLinkUrl_xpath = "//*[@id='jobListings']/tbody/tr[";
        String second_part_jobLinkUrl_xpath = "]/td/a";

        WebElement webJobLinkUrl = driver
                .findElement(By.xpath(first_part_jobLinkUrl_xpath + (j + 2) + second_part_jobLinkUrl_xpath));
        jobLinkUrl.add(webJobLinkUrl.getAttribute("href"));
        //                   
        String final_jobLinkTitle_xpath = first_part_jobLinkTitle_xpath + (j + 2)
                + second_part_jobLinkTitle_xpath;
        String final_jobShortDesc_xpath = first_part_jobShortDesc_xpath + (j + 3)
                + second_part_jobShortDesc_xpath;

        WebElement webJobLinkTitle = driver.findElement(By.xpath(final_jobLinkTitle_xpath));
        String jobLinkTitle = webJobLinkTitle.getText();

        WebElement webJobShortDesc = driver.findElement(By.xpath(final_jobShortDesc_xpath));
        String jobShortDesc = webJobShortDesc.getAttribute("innerHTML");

        System.out.println("Job Title = " + jobLinkTitle);
        System.out.println();

        System.out.println("Short Description of Job = " + jobShortDesc);
        System.out.println();

        System.out.println("Link URL of Job" + jobLinkUrl);
        System.out.println();
    }

    //        // GoTo 'Full Job Description'
    for (int i = 0; i < jobLinkUrl.size(); i++) {

        driver.navigate().to(jobLinkUrl.get(i));
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        //          
        WebElement webJobFullDescData = driver
                .findElement(By.xpath("//*[@id='jobDetails']/div[2]/table/tbody/tr[1]/td"));
        String jobFullDescData = webJobFullDescData.getText();
        //     
        System.out.println("Job Full Description Data" + jobFullDescData);
        System.out.println();

    }
}

From source file:CarTest1.java

@Test
//Verify that page is loaded and all expected data are visible
public void test1() throws Exception {
    (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> {
        WebElement e = d.findElement(By.tagName("tbody"));
        List<WebElement> rows = e.findElements(By.tagName("tr"));
        Assert.assertThat(rows.size(), is(5));
        return true;
    });/*from   ww w. j ava2  s  . com*/
}

From source file:CarTest1.java

@Test
//Verify the filter functionality 
public void test2() throws Exception {
    //No need to WAIT, since we are running test in a fixed order, we know the DOM is ready (because of the wait in test1)
    WebElement element = driver.findElement(By.id("filter"));
    element.sendKeys("2002");
    WebElement e = driver.findElement(By.tagName("tbody"));
    List<WebElement> rows = e.findElements(By.tagName("tr"));
    Assert.assertThat(rows.size(), is(2));
}

From source file:CarTest1.java

@Test
//Clear text and verify 5 rows
public void test3() throws Exception {
    tearDown();/*  w ww .j  a  v  a 2 s. c om*/
    setup();
    (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> {
        WebElement e = d.findElement(By.tagName("tbody"));
        List<WebElement> rows = e.findElements(By.tagName("tr"));
        Assert.assertThat(rows.size(), is(5));
        return true;
    });
}

From source file:CarTest1.java

@Test
public void test5() throws Exception {

    WebElement row = driver.findElement(By.xpath("//tbody/tr[td='938']"));
    WebElement a = row.findElements(By.tagName("a")).get(0);
    a.click();/*  w  w w  .j  a  v  a  2s  .  c om*/
    WebElement desc = driver.findElement(By.name("description"));
    desc.clear();
    desc.sendKeys("Cool car");

    WebElement submit = driver.findElement(By.id("save"));
    submit.click();

    (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> {
        WebElement newRow = d.findElement(By.xpath("//tbody/tr[td = '938']"));
        String b = newRow.findElements(By.tagName("td")).get(5).getText();
        Assert.assertEquals("Cool car", b);
        return true;
    });
}

From source file:CarTest1.java

@Test
public void test6() throws Exception {
    WebElement newCar = driver.findElement(By.id("new"));
    newCar.click();/*from w ww .j  a  va2  s  .c  om*/
    WebElement submit = driver.findElement(By.id("save"));
    submit.click();

    WebElement e = driver.findElement(By.tagName("tbody"));
    List<WebElement> rows = e.findElements(By.tagName("tr"));
    Assert.assertTrue(driver.findElement(By.id("submiterr")).isDisplayed());
    Assert.assertEquals("All fields are required", driver.findElement(By.id("submiterr")).getText());
    Assert.assertThat(rows.size(), is(5));
}

From source file:CarTest1.java

@Test
public void test7() throws Exception {
    WebElement newCar = driver.findElement(By.id("new"));
    newCar.click();// w  w  w.  java  2  s  .co m

    WebElement year = driver.findElement(By.name("year"));
    WebElement reg = driver.findElement(By.name("registered"));
    WebElement make = driver.findElement(By.name("make"));
    WebElement model = driver.findElement(By.name("model"));
    WebElement desc = driver.findElement(By.name("description"));
    WebElement price = driver.findElement(By.name("price"));
    WebElement submit = driver.findElement(By.id("save"));

    year.sendKeys("2008");
    reg.sendKeys("2002-5-5");
    make.sendKeys("Kia");
    model.sendKeys("Rio");
    desc.sendKeys("As new");
    price.sendKeys("31000");

    submit.click();

    (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> {
        WebElement e = d.findElement(By.tagName("tbody"));
        List<WebElement> rows = e.findElements(By.tagName("tr"));
        Assert.assertThat(rows.size(), is(6));
        return true;
    });
}

From source file:testTheClient.java

@Test
public void domLoaded5RowsinTbody() {
    WebElement tableBody = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            });//  w  w  w.  java  2  s .c  o  m
    Assert.assertThat(tableBody.findElements(By.tagName("tr")).size(), is(5));
}

From source file:testTheClient.java

@Test
public void lookUp2002() throws Exception {
    WebElement element = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return driver.findElement(By.xpath("//*[@id=\"filter\"]"));
            });//  w  w  w.  j  a va 2s . c o m
    element.clear();
    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:testTheClient.java

@Test
public void removeFilterTest() throws Exception {
    WebElement element = driver.findElement(By.id("filter"));
    element.sendKeys(Keys.BACK_SPACE);/*  w w w. java 2s.c o  m*/
    WebElement tableBody = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            });
    List<WebElement> rows = tableBody.findElements(By.tagName("tr"));
    Assert.assertThat(rows.size(), is(5));
}