Reputation: 51
I am trying to locate the xpath that matches the exact text "Manufacturer" but it is not working.
I cannot use "contains" as there is another xpath element that has text "Discontinued by Manufacturer" in it. I need a solution where I can use the same thing on other urls which sometimes doesn't have other elements containing the text "Manufacturer" like "Discontinued by Manufacturer" and has only just the "Manufacturer"
The url is https://www.amazon.com/BEAKEY-Foundation-Blending-Flawless-Multi-colored/dp/B01F36JEXE/ref=sr_1_22?dchild=1&keywords=cosmetics&qid=1625014752&sr=8-22 if anyone needs a reference
here is what I'm seeing when I try to search for "Manufacturer" image of error
Upvotes: 0
Views: 179
Reputation: 163625
If you want to match the content of a text node or element exactly, use the "=" operator, not contains()
.
It's a common XPath mistake to use contains()
in place of "=". In fact, it's a common mistake to guess what a function does from its name, rather than reading the spec.
Upvotes: 1
Reputation: 29382
There are 4 Manufacturer on that page.
you can try this xpath :
(//ul[contains(@class, 'a-unordered-list')]/descendant::span[@class='a-text-bold'])[1]
to match
Is Discontinued By Manufacturer : No
and
(//ul[contains(@class, 'a-unordered-list')]/descendant::span[@class='a-text-bold'])[5]
to match :
Manufacturer : BEAKEY
Upvotes: 1
Reputation: 33361
Since there are 2 span elements with text "Manufacturer" this should fit there:
"(//span[contains(text(),'Manufacturer')])[last()]"
Upvotes: 1