I have this case where i have a filter this filter is stuck between 88 and 89.
The probleme is the values i can have are 88,36 and 88,95.
My actualy case :
<div class="d-flex-inline">
<span>88,97</span>
<span>€/HT</span>
</div>
When i tried to give him this Xpath it always return true either i give it a correct condition or not and always find the element.
/div[@class="prix"]/div[2]/div[2]/span[1][boolean(number(text()) > 80) = false] Returns true
/div[@class="prix"]/div[2]/div[2]/span[1][boolean(number(text()) < 80) = false] Returns true
the xpath i want is one where i can give the initial filter values 88 and 89 i was planning to add the other condition if the bool worked but it didn’t can you guys please assist me with this one.
FYI : When i tried
//div[@class="prix"]/div[2]/div[2]/span[1][number(text()) = 88,97]
it didn’t work and didnt find the element
>Solution :
The XPath definition of a Number only allows . as the decimal separator, not , The number() function uses that definition, and returns NaN ("not a number") for any string not in the expected format.
Since NaN can’t be defined as either less than or greater than any specific value, the condition always returns false. (Your title says it always returns true, but that’s because you’re inverting it with = false).
You can use the translate() function to replace the , with a . and then the number should parse correctly:
number(translate(text(), ",", "."))
In context:
/div[@class="prix"]/div[2]/div[2]/span[1][boolean(number(translate(text(), ",", ".")) > 80) = false]
Incidentally, boolean(foo) = false can more simply be written with the not function as not(boolean(foo)), or just not(foo):
/div[@class="prix"]/div[2]/div[2]/span[1][not(number(translate(text(), ",", ".")) > 80)]