how to validate whole contents of the web table in selenium

  • Web table with cell values

    How do i validate all column values based on technologies.
    e.g For

    • Technology A - values should be 0 0 1

    • Technology B - Values should be 1 0 100

    and so on.

    My code looks something like this

    str1 = driver.findbyxpath.gettext();     
                    cell1 = driver.findElement(By.xpath("//*[@id=\"siaSummaryTable\"]/div[2]/div/div/div/div/div/table/tbody/tr[1]/td[2]")).getText();
                    cell2 = driver.findElement(By.xpath("//*[@id=\"siaSummaryTable\"]/div[2]/div/div/div/div/div/table/tbody/tr[1]/td[3]")).getText();
                    cell3 = driver.findElement(By.xpath("//*[@id=\"siaSummaryTable\"]/div[2]/div/div/div/div/div/table/tbody/tr[1]/td[4]")).getText();
                    Assert.assertEquals("Not valid data,"0",cell1);
                    Assert.assertEquals("Not valid data","0",cell2);
                    Assert.assertEquals("Not valid data","0",cell3);
                    System.out.println("Asserstion for A Successfull");

    But code will be much complex if i validate for all technologies and respective column values.
    what is the other solution ?
    p.s - Please ignore the xpath with multiple divs. This is just for testing purpose.

  • You can create a method that would validate data in one row of a table. It could accept the row number and expected values. So you would just reuse that method for all the table rows.

    This would make your code less complex and more readable.

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2