Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

     <table class="footable table table-hover table-striped table-bordered" 
     cellspacing="0" cellpadding="6" border="0">
     <thead>
     <tr class="CartBlueHeader">
     <th align="10%">PNR No</th>
     <th width="23%" align="center">Origin</th>
     <th width="22%" align="center">Destination</th>
     <th width="10%">Departure</th>
     <th width="10%">Return</th>
     <th width="10%">Amount</th>
     <th width="15%"/>
     </tr>
   </thead>
    <tbody>
      <tr class="BGLightblue font11">
       <td align="left">   Q2S2SO </td>
       <td align="left">   Dubai Intl Airport </td>
       <td align="left">   Hindustan Airport </td>
       <td align="center"> 30 Sep 17 </td>
       <td align="center">-</td>
       <td align="left"> 608.00 SAR   </td>
       <td align="left">
    </tr>
    </tbody>
    </table>

Want to retrieve the values elements based on its header value in the table. How do i proceed with this any idea.

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
260 views
Welcome To Ask or Share your Answers For Others

1 Answer

Follow the pattern only

// Grab the table 
WebElement table = driver.findElement(By.id("divListView")); 

// Now get all the TR elements from the table 
List<WebElement> allRows = table.findElements(By.tagName("tr")); 

// And iterate over them, getting the cells 
for (WebElement row : allRows) { 
    List<WebElement> cells = row.findElements(By.tagName("td")); 

    // Print the contents of each cell
    for (WebElement cell : cells) { 
        System.out.println(cell.getText());
    }
}

Hope it will help you


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...