-1

I want to get a value of "square" (for example, 201). I tried to do so, as described here, but it doesn't work:

./li[attributeTitle='Этаж']

Html code:

<div class = "A">
    <ui class = "B">
        <li>
            <span class = "attributeTitle"> Floor </span>
            <span class = "attributeValue"> 3 </span>
        </li>
        <! A random more items "li" >
        <li>
            <span class = "attributeTitle"> Square </span>
            <span class = "attributeValue"> 201 </span>
        </li>
        <li>
            <span class = "attributeTitle"> Nrooms </span>
            <span class = "attributeValue"> 4 </span>
        </li>
    </ui>
</div>

Thanks for any help.

shicey
  • 3
  • 2

1 Answers1

1

You can use contains() function in xpath to check whether text contains some string:

"//div[@class='attributeTitle'][contains(text(),'Square')]"

This gets you this node:

<span class = "attributeTitle"> Square </span>

To get the value node that is right below it you can use following-sibling::span:

"//div[@class='attributeTitle'][contains(text(),'Square')]/following-sibling::span[1]"

And adding [1] to indicate that we want only the first sibling in case there are more than one sibling. You can also use [class='attributeValue'] instead to indicate that we only want siblings that have this particular class, or not use anything at all there if you trust there will only be 1 sibling.

Mathias Müller
  • 22,203
  • 13
  • 58
  • 75
Granitosaurus
  • 20,530
  • 5
  • 57
  • 82
  • `//div[@class='attributeTitle' and contains(text(),'Square')]` also works – becixb Jan 27 '17 at 02:38
  • also if what you posted is the complete DOM, then you don't need the [1] when getting the value since there is only one span node after the square element.. – becixb Jan 27 '17 at 02:40