user3203342
user3203342

Reputation: 227

xpath: how to get the specific text using xpath?

the html is like this:

<div id='id'>
    <a href>abc</a>
"xyz"
</div>

I want to use xpath to get the xyz (I use it in capybara), but my xpath can't work

... //div[@id='id'].text

it returns abcxyz

how can I get it?

Upvotes: 0

Views: 148

Answers (1)

Kevin Sandow
Kevin Sandow

Reputation: 4033

Text is its own text node, so the correct selector would be:

.//div[@id='id']/text()

Upvotes: 1

Related Questions