Reputation: 69
I am trying to use the OR operator where I want either expression to work.
The expression work individual but not together can you help please see below
//*[[@class='eline'][1]/following-sibling::tr] OR [[@class='eline'][1]]
Hi,
Here is a better example for you below so I am happy with your first solution as this selected everything but then I wanted to select the element where alt="Ab" as this elements position may change so I want the xpath to be a dynamic as possible
<tr class="eline">
<tr>
<td class="norm" nowrap=""/>
<td class="norm" nowrap="">
<td class="norm" nowrap="">
<td class="norm" nowrap="">cccc cccc </td>
<td class="norm" nowrap="">99999 </td>
<td class="norm" nowrap=""/>
<td>
<td class="norm" nowrap="">
<img width="20" vspace="0" border="0" hspace="0" height="15" alt="Ab" name="abs3" src="images/sp_abs.gif"/>
</td>
<td class="norm" nowrap="">
<td class="norm" nowrap="">testcase33 testcase33 </td>
<td class="norm" nowrap="">33100 </td>
<td class="norm" nowrap=""/>
<td class="norm" nowrap=""/>
</tr>
<tr class="eline">
<tr>
<tr class="eline">
<tr>
<tr>
Upvotes: 1
Views: 116
Reputation: 237855
I think you are attempting to select:
class
attribute eline
tr
elementsThe simplest way is simply to combine the two selectors that did work using the union |
operator:
//*[@class='eline'][1]/following-sibling::tr | //*[@class='eline'][1]
For instance, with this XML:
<table>
<tr name="first"/>
<tr class="eline" />
<tr name="third"/>
<tr name="fourth"/>
</table>
the above XPath would give
<tr class="eline"/>
<tr name="third"/>
<tr name="fourth"/>
Presuming you want to find an element img[@alt="Ab"]
from within the elements selected by the code above, you can do it with something like this:
(//*[@class='eline'][1]/following-sibling::tr | //*[@class='eline'][1]) // img[@alt="Ab"]
Upvotes: 1