My HTML code is:
<table>
<tr>
<td class="data1"><p>1</td></td>
<td class="data1"><p>2</td></td>
<td class="data1"><p>3</td></td>
<td class="data1"><p>4</td></td>
</tr>
<tr>
<td class="data1"><p>5</td></td>
<td class="data1"><p>6</td></td>
<td class="data1"><p>7</td></td>
<td class="data1"><p>8</td></td>
</tr>
</table>
My query is:
xpath='//tr//td[@class="data1"][4]/p'
The results is:
<p>4</p>
<p>8</p>
The results is correct! but, if I want to get example:
<p>3</p> <p>4</p>
<p>7</p> <p>8</p>
So
[3]/p and [4]/p
How to get these two elements each <tr>
?
Thank you so much!
The syntax for locating elements through XPath- Multiple Attribute can be written as: //<HTML tag>[@attribute_name1='attribute_value1'][@attribute_name2='attribute_value2]
//div[@class='content'][2] means: Select all elements called div from anywhere in the document, but only the ones that have a class attribute whose value is equal to "content". Of those selected nodes, only keep those which are the second div[@class = 'content'] element of their parent.
selects the union of all nodes selected by expr1 and all nodes selected by expr2. The | character denotes the XPath union operator. You can use the union operator in any case when you want the union of the nodes selected by several XPath expressions to be returned.
For example if both text fields have //input[@id='something'] then you can edit the first field xpath as (//input[@id='something'])[1] and the second field's xpath as (//input[@id='something'])[2] in object repository.
I think what you might be looking for is something along the lines of
[position() > 2]
which retrieves all elements after the first two.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With