簡體   English   中英

Puppeteer 找到 svg 使用 xlink:href

[英]Puppeteer find svg use xlink:href

我有以下 html:

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

現在<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.

改變

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

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

或者

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

但關於名稱空間,另請參閱XPath 如何處理 XML 名稱空間?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM