Search code examples
xpathuniondata-extraction

xPath union statement with functions


thanks in advance for reading.

I'm using $x() xPath evaluator of Chrome console.

I need to match something shaped like $x("e1 | e2").

In my case:

  • e1:

    (//div[@class='seven columns omega']//form//div[@class='items_left']//text())[2]

  • e2

    (substring-after(//div[@class='seven columns omega']//span[@class='sold_out']/text(),' - '))

They both works in the single way but if i want to combine them I just get stuck in

"Failed to execute 'evaluate'..."

PS The problem is e2 function substring-after, without it the union works.

Any Ideas? Here are the 2 sources i'm trying to extract:

Thanks again :)


Solution

  • Based on your comments that you want string values and expect only one of those expressions to find something on the same page you could simply try

    var result = $x("string((//div[@class='seven columns omega']//form//div[@class='items_left']//text())[2])") + $x("(substring-after(//div[@class='seven columns omega']//span[@class='sold_out']/text(),' - '))")