1

Any idea which XPath leads to this:

<a class="sc-2wok21-1 hlSSAt">
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M14.707 6.293L20.414 12l-5.707 5.707-1.414-1.414L16.585 13H4v-2h12.585l-3.292-3.293 1.414-1.414z" 

I'm trying things like "//a[@class="sc-2wok21-1 hlSSAt"]/svg or //a[@class="sc-2wok21-1 hlSSAt"]/[local-name()=‚svg‘] but nothing works.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Bao Hoang
  • 53
  • 3
  • Your first one looks nearly right, but I am not sure you can do `@class="sc-2wok21-1 hlSSAt"` - I wonder if you need two `@class` contains. – halfer Jun 16 '22 at 23:35
  • Maybe have a look at this: https://stackoverflow.com/a/44028602 – halfer Jun 16 '22 at 23:36
  • The key here is experimentation. Get `//a/svg` working first, then introduce one class contains, then see if you can do both. Use an online XPath "Fiddle" app. – halfer Jun 16 '22 at 23:37

1 Answers1

0

Your second XPath is close in its recognition that svg is in a namespace.

Change

//a[@class="sc-2wok21-1 hlSSAt"]/[local-name()=‚svg‘]

to

//a[@class="sc-2wok21-1 hlSSAt"]/*[local-name()="svg"]

to select the svg element.

Alternatively, declare a namespace prefix and use it in the XPath rather than defeating namespaces with the local-name() hack. See How does XPath deal with XML namespaces?

kjhughes
  • 106,133
  • 27
  • 181
  • 240