1

I have the following html:

<button data-testid="likeButton">
    <svg aria-hidden="true">
        <use xlink:href="/logo"></use>
    </svg>
    <span>Like</span>
</button>

Now the <use xlink:href could be either /logo or /logo-filled

How can I write an xpath expression in Puppeteer to get these?

I have tried this:

//*[name()='use'][contains(@*='logo')]

But when I test it, i get the error:

Unable to perform XPath operation. The prefix "xlink" for attribute "xlink:href" associated with an element type "use" is not bound.
kjhughes
  • 106,133
  • 27
  • 181
  • 240
strangeQuirks
  • 4,761
  • 9
  • 40
  • 67

1 Answers1

1

Change

//*[name()='use'][contains(@*='logo')]
                             ^

to

//*[name()='use'][contains(@*,'logo')]
                             ^

or

//use[starts-with(@*,'/logo')]

but regarding namespaces, see also How does XPath deal with XML namespaces?

kjhughes
  • 106,133
  • 27
  • 181
  • 240