I was wondering if you could pick your brain with a brain teaser.
To setup the issue, we have this situation: I have an unordered list, and each list item containing 1 Span and 1 div.
<li class="offer-params__item">
<span class="offer-params__label">Putere</span>
<div class="offer-params__value">150 CP</div>
</li>
I was trying to use the XPath below to get the div contents from the list items.
//*[@id="parameters"]/ul[1]/li[8]/div
I noticed that items are not always in the same order, so item 8 is not always the horsepower or in this case "150 CP", so I need to actually search for the Div value using the Span value which is always the same (on the same level as the div).
Is there a way I can search using xPath by content of the span - "Putere" in this case, and get the content of the Div - "150 CP" in this case?
I'm thinking I need to search for span = "Putere", get the parent out out of that and get the div child, but the syntax is above my knowledge.
CodePudding user response:
If I understand you correctly, the xpath you're looking for should be something like
//li[span="Putere"]/div
Try it on your actual html and see if it works.