Home > Software engineering >  Why my xpath expression doesn't solved the question?
Why my xpath expression doesn't solved the question?

Time:11-20

I practice in building xpath expression. I found the following task:

Select the small apple and the big orange

<div class='table'>
   <plate id="fancy">
       <apple class="small"/>
   </plate>
   <plate>
       <orange class="small"/>
       <orange/>
   </plate>
   <pickle class="small"/>
</div>

I can't understand why the following expression doesn't solve the question:

//apple[@class='small']|//orange[last()]

CodePudding user response:

Try this

//apple[@class='small'] | //orange[@class='small'] 

Output:

<apple class="small"/>
<orange class="small"/>

CodePudding user response:

This site is very opinionated, i.e. it does not accept all correct answers, but only specific ones.

What they want here is:

//plate[@id='fancy']/apple | //orange[last()]

CodePudding user response:

To select the small apple and the big orange you need to use:

//apple[@class='small']|//orange[position()=last()]

Snapshot:

small_apple_big_orange

  • Related