xPath union statement with functions - xpath

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:
e1-case
e2-case
Thanks again :)

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(),' - '))")

Related

Query() function in Google Sheets yields stray value: Why, and how can I fix it?

I would like to run a query statement that adds a bullet (●) to each row of output.
Here is my sample data:
Here is the query:
=query($A$1:$B$3,"SELECT '●',A,B",0)
Here is the result:
Why does the first stray line appear in the output ["●"()], and how can I write the query so that it yields only rows 2, 3, 4 and not the first row?
Note that the actual data is much more complicated than this, so solving it with a filter or array does not work well. I need a query solution. And I'd really like to know why that first line is appearing in the first place.
Thanks for the help.
KLS
=QUERY($A$1:$B$3, "SELECT '●', A, B LABEL '●' ''", 0)
This assigns an empty string to the label for that column, thus eliminating the label row.

Power Query - Multiple OR statement with values

I've been doing research on this and I find a plethora of articles related to Text, but they don't seem to be working for me.
To be clear this formula works, I'm just looking to make it more efficient. My formula looks like:
if [organization_id] = 1 or [organization_id] = 2 or [organization_id] = 3 then "North" else if … where organization_id is of type "WholeNumber"
I'd like to simplify this by doing something like:
if [organization_id] in {1, 2, 3} then "North" else if …
I've tried wrapping in Parenthesis, Braces, & Brackets. Nothing seems to work. Most articles are using some form of text.replace function and mine is just a custom column.
Does MCode within Power Query have any efficiencies like this or do I have to write out each individual statement like the first line?
I've had success with the a List.Contains formulation:
List.Contains({1,2,3}, [organization_id])
The above checks if [organization_id] is in the list supplied in the first argument.
In some cases, you may not want to hardcode a list as shown above but reference a table column instead. For example,
List.Contains(TableWithDesiredIds[id_column], [organization_id])

xpath query not considering the decimal

I'm using the following xpath query
//div/span[#class='you-pay-price ' and 1]
but I'm getting the result is in thousands. that is if the price is 250.9 the result would 250,900
how can I fix this issue. Link to the source
regards,
You can try something like this to keep only one decimal :
(substring-before(//div/span[#class='you-pay-price'],' KD')*100)div 100
Output : 259.9

How do I use multiple OR operators in XPath

I am trying to combine three different OR opearators
[FindsBy(How = How.XPath, Using = "[//img[contains(#src,'/BankPayProcessing-Icon.png')]|//span[contains(text(), 'Bank Pay Processing')]|//span[contains(text(), 'BankPay Processing')]")]
However, this is not working. I am not able to figure out why.
Can I get some help please?
The "or" operator in XPath is not "|", it is "or".
The "|" operator forms the union between two node-sets, it cannot be applied to a boolean value (such as the result of (A=B)).
It's easy to be misled when you see something like match="x|y" into thinking it matches "x or y". Actually it matches the union of x and y, that is, anything in the set of all x and y elements.

xpath, how to select more than one item using indices

In this query, I select the 3rd
//tablecontainer/table/tbody/tr/td[3]
How do I select both the 3rd and 4th 's?
To get both the 3rd and 4th tds, you can use the expression:
//tablecontainer/table/tbody/tr/td[position() >= 3 and position() <= 4]
//tablecontainer/table/tbody/tr/td[position()=3 or position()=4]
If you can use XPath 2.0 you could use following trick
//tablecontainer/table/tbody/tr/td[position() = (1,2,4)]
Test position() = (1,2,4) means something similar as IN from SQL. Notice the brackets in (1,2,4) part.

Resources