-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.

2
  • How is it working? What do you expect and what do you see instead? Commented Jan 26, 2017 at 15:22
  • Please show a complete, but minimal, input HTML document. Thanks. More help: stackoverflow.com/help/mcve. Commented Jan 26, 2017 at 15:27

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

//div[@class='attributeTitle' and contains(text(),'Square')] also works
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..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.