[英]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.