XPath: logical OR

Please help using the logical OR operator in XPATH and select one query from these two:

1) .//span[@class=\'fob12\']

2) .//p[@class=\'fob12\']

They differ only in tag.

+7
source share
5 answers

One more (with OR request):

 ".//*[(self::p or self::span) and @class = 'fob12']" 
+9
source

Do you want a union expression that is | therefore XPath will:

  .//span[@class="fob12"] | .//p[@class="fob12"] 
+8
source

Maybe I missed something, but the following should work !?

 .//span[@class=\'fob12\'] | .//p[@class=\'fob12\'] 
+4
source

I would write it as .//(p|span)[@class='fob12'] . But I think it requires XPath 2.0 IIRC.

+2
source

Another XPath:

 .//*[(self::p | self::span)[@class = 'fob12']] 
0
source

All Articles