Reputation: 113
I am trying to get either a parent li or tr from an element with specific text.
As it stands I am just trying different separate xpath expressions, but I am curious if I can just make one that goes something like this:
'//[tr | li]//*[contains(text(), "Some Text")]'
or
'//*[contains(text(), "Some Text")]/[ancestor::tr | ancestor::li]'
I have found that I can just string the statements together like so:
'//li[descendant::*[contains(text(), "Some Text")]] | //tr[descendant::*[contains(text(), "Some Text")]]'
but that isn't ideal either.
Upvotes: 1
Views: 715
Reputation: 5905
Assuming the following XPath is your desired expression :
//li[descendant::*[contains(text(), "Some Text")]] | //tr[descendant::*[contains(text(), "Some Text")]]
You can do :
(//tr|//li)[.//*[contains(text(), "Some Text")]]
Upvotes: 1