How do I use XPath to find the values of cells in a table

  • The structure of the Html I need to work with is shown in the screenshots below.

    Image 1

    Image 2

    I need to get the values of the first and third column of each data row in the table. There is nothing unique about the rows or cells.

    I've tried:

     //String CPONEW="//table[@id='GridView1']/tbody/tr[2]['@id!= or @class=!"+j+"']/td[1]"; 

    When I try to use this xpath I only get the first tr[2]/td[1] val but I need to get each tr[2] to tr[12] / td[1] and td[3] values

  • Try the below code:

    List  tableRows = table.findElements(By.xpath("tr"));
    List  tableCells= table.findElements(By.xpath("tr/td"));
    //you can assign to String 
    String FirstColumn=tableCells.get(1);

Log in to reply

Suggested Topics

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