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
  • 98,039
  • 18
  • 159
  • 218
strangeQuirks
  • 3,639
  • 6
  • 31
  • 51

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
  • 98,039
  • 18
  • 159
  • 218