【问题标题】:Puppeteer find svg use xlink:hrefPuppeteer 使用 xlink:href 查找 svg
【发布时间】:2020-09-28 19:39:58
【问题描述】:

我有以下html:

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

现在&lt;use xlink:href 可以是/logo/logo-filled

如何在 Puppeteer 中编写 xpath 表达式来获取这些?

我试过这个:

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

但是当我测试它时,我得到了错误:

Unable to perform XPath operation. The prefix "xlink" for attribute "xlink:href" associated with an element type "use" is not bound.

【问题讨论】:

    标签: html xml svg xpath puppeteer


    【解决方案1】:

    改变

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

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

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

    但关于命名空间,另请参阅How does XPath deal with XML namespaces?

    【讨论】:

      猜你喜欢
      • 2016-05-07
      • 2017-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-07
      • 2016-06-09
      • 1970-01-01
      相关资源
      最近更新 更多