Here is the html I am working on, the concept is to loop through the table and fetch all the td values. And based on the first td value, fetch the second td with tag strong inside the td tag e.g: I have to fetch Case ID so i need to first check the first td value, if it is Case id than based on the i need to save the value inside the strong tag in a variable and use this value in the code
<table class="table table-condensed">
<tbody><tr>
<td>Case ID: </td>
<td> <strong>3406872</strong></td>
</tr>
<tr>
<td>Date of Case: </td>
<td><strong>24-09-2018 05:54 AM</strong></td>
</tr>
<tr>
<td>Name: </td>
<td><strong> </strong></td>
</tr>
<tr>
<td>Email: </td>
<td><strong><a href="mailto:"></a></strong></td>
</tr>
<tr>
<td>Phone:</td>
<td><strong></strong></td>
</tr>
<tr>
<td>Phone Mobile:</td>
<td><strong></strong></td>
</tr>
<tr>
<td>Address: </td>
<td>
<strong><br> </strong>
</td>
</tr>
<tr>
<td>Store Of Purchase: </td>
<td><strong>JBNZ RICCARTON (029)</strong></td>
</tr>
<tr>
<td>Purchase Date: </td>
<td><strong>10-02-2017</strong></td>
</tr>
<tr>
<td>Purchase Price: </td>
<td><strong>$463.00</strong></td>
</tr>
<tr>
<td>Receipt/Tax invoice Number:</td>
<td><strong>0307618717 41258 029 17</strong></td>
</tr>
<tr>
<td>Floor Stock:</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>Repaired Previously: </td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>Abuse/Misuse:</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>Marked/Scratched: </td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>Marked/Scratched Comment: </td>
<td><strong></strong></td>
</tr>
<tr>
<td>Fault Report:</td>
<td><strong>Product gives electric shock to user while in use.</strong></td>
</tr>
<tr>
<td>Fault Code:</td>
<td><strong>Other (I)</strong></td>
</tr>
<tr>
<td>Retailer can Replicate: </td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>If not, why not: </td>
<td><strong></strong></td>
</tr>
<tr>
<td>Within automatic replacement period:</td>
<td>
<strong>
No </strong>
</td>
</tr>
<tr>
<td> Within warranty period:</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>Within assess for repair period:</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>Liability of repair:</td>
<td><strong>Vendor</strong></td>
</tr>
<tr>
<td>Disclaimer:</td>
<td><strong>No</strong></td>
</tr>
<tr>
<td>Case Type:</td>
<td><strong>Requested in store</strong></td>
</tr>
<tr>
<td>Case Status:</td>
<td class="">
<strong> Closed, replaced </strong>
</td>
</tr>
The Code that i am writing is:
List<WebElement> allrows= driver.findElements(By.xpath("//table[@class='table table-condensed']/tbody/tr"));
int rows = allrows.size();
//System.out.println(rows);
for(int i=0; i<rows;i++) {
List<WebElement> Columns= allrows.get(i).findElements(By.tagName("td"));
for(int j=0;j<2;j++) {
String CaseV = Columns.get(j).getText();
System.out.println(CaseV);
It is fetching me all the values like this:(This is how it comes on console) Case ID:
3412943
Date of Case:
26-09-2018 13:27 PM
Name:
j k
How can i achieve this? Can Somebody help me with this? Let me know if more information is needed?