Reputation: 11
So I have a situation where there are two Xpaths. Xpath1 and Xpath2. I have to take Xpath1 if it is there. And if not I have to take Xpath2.
I tried using Xpath1 | Xpath2 .
Issue with this is, if both are present it's Taking Xpath2.
I don't need the Xpath2 if Xpath1 is already there.,
Upvotes: 1
Views: 59
Reputation: 163262
If the result is a single node, you can do (path1 | path2)[1]
.
If the result is a node-set of arbitrary size, then it's more difficult, especially in XPath 1.0 (which is what you're using with Selenium). You might have to resort to something like (path1 | self::node()[not(path1)]/path2)
.
Upvotes: 1