Skip to content Skip to sidebar Skip to footer

Xpath Expression To Select Nodes Based On Presence Of Child Node?

I'm trying to use Xpath to find all
s with a given CSS class (.product).

Solution 1:

You were almost there. You don't need []s around the img sub-path:

//div[@class="product" and not(img[@alt = "sold out"])]

Another way to write essentially the same thing is:

//div[@class="product" and not(img/@alt = "sold out")]

Lastly, since class attributes can contain more than one class, it's often better to use contains() to check for classes:

//div[contains(concat(' ', @class, ' '), " product ") and not(img/@alt = "sold out")]

Solution 2:


Solution 3:

you are making a small mistake it should be

//div[@class="product"]/img [ @alt!="sold out"]


Post a Comment for "Xpath Expression To Select Nodes Based On Presence Of Child Node?"