From the below table I need immediate row elements using Xpath or "css-selector" or Selenium API :- element.findelements. Please help.
<table id ="Main">
<tbody>
<tr id="row_1">
<tr id="row_1_1">
<tr id="row_1_1_1">
</tr>
</tr>
</tr>
<tr id="row_2">
</tr>
<tr id="row_3">
<tr id="row_3_1">
</tr>
</tr>
</tbody>
</table>
Expected Output:-
[<tr id="row_1">,<tr id="row_2">,<tr id="row_3">]
Imp Note:- I am looking for a generic solution. Sometimes tbody wont be present in the table. I am having Table WebElement with me.
You can use xpath union operator (
|
) to combine multiple xpath expressions, f.e one to handle the case whentbody
exists, and another for the case whentbody
doesn't exist :