[xpath] XPath OR operator for different nodes

How can I do with XPath:

//bookstore/book/title or //bookstore/city/zipcode/title

Just //title won't work because I also have //bookstore/magazine/title

p.s. I saw a lot of or examples but mainly with attributes or single node structure.

This question is related to xpath

The answer is


It the element has two xpath. Then you can write two xpaths like below:

xpath1 | xpath2

Eg:

//input[@name="username"] | //input[@id="wm_login-username"]

If you want to select only one of two nodes with union operator, you can use this solution: (//bookstore/book/title | //bookstore/city/zipcode/title)[1]