Andrii Yurchuk
Andrii Yurchuk

Reputation: 3270

XPath strict contains() function

I'm using xpath's contains function to find elements that contain some text, like this:

//td[contains(text(),'foo')]

But if the page, for example, contains two td elements, that contain foo and foo bar respectively, the above xpath will return both of them. Is there any kind of strict contains, that will return only the element with text foo, but not the one with foo bar?

Upvotes: 1

Views: 1660

Answers (2)

Siva Charan
Siva Charan

Reputation: 18064

Try this way:-

//td[normalize-space() = 'foo']

Upvotes: 0

bobbymcr
bobbymcr

Reputation: 24167

By "strict contains" do you actually mean a simple equality test? If so you should be able to do that using //td[text() = 'foo'].

Upvotes: 6

Related Questions