Issue
I am new to XPath and confused. Anyone can have a quick glance and see what is wrong in my syntax?
I'm trying to select all direct child div's
of id="list-overview"
which has two child nodes somewhere down their tree containing data-price<=20
and a div containing "Orange" text
let xy = $x(`//*[@id="list-overview"]/div[./div/a/div/div/div[@data-price<=20]][./div/a/div/div[@class='fruit'][contains(.,'Orange')]])`)
to break it up. I have tested these two separately and they worked.
`//*[@id="list-overview"]/div[./div/a/div/div/div[@data-price<=20]]`
`//*[@id="list-overview"]/div[./div/a/div/div[@class='fruit'][contains(.,'Orange')])]`
I just can't seem to combine them somehow and not sure what I'm doing wrong?
EDIT:
Tried the suggestions and the following xpath doesn't throw an exception anymore. But it returns empty Array while there are elements matching price < 20 and fruit="Orange"
$x(`//*[@id="list-overview"]/div[./div/a/div/div/div[@data-price<=20] and ./div/div/a/div/div[@class='fruit'][contains(.,'Orange')]]`)
Solution
If I understand your idea, you are missing the logical and
between these 2 conditions. I corrected the XPath expression accordingly. Please try this:
let xy = $x(`//*[@id="list-overview"]/div[./div/a/div/div/div[@data-price<=20] and ./div/a/div/div[@class='fruit'][contains(.,'Orange')]])`)
UPD
Please try this:
let xy = $x(`//*[@id="list-overview"]/div[.//div[@data-price<=20] and .//div[@class='fruit'][contains(.,'Orange')]])`)
Answered By - Prophet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.