html - Puppeteer 使用 xlink:href 查找 svg
问题描述
我有以下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 名称空间?
推荐阅读
- azure - Azure APIM 策略
- java - Quarkus 的自定义配置源
- c# - 如何随机播放列表
- > 没有下一个和上一个列表有重复
- python - 来自 get_queryset(self) 的 Django 排序搜索结果
- javascript - 如何随机化 EJS 变量的顺序
- node.js - Firebase Cloud Functions:触发器上的函数超时
- java - Java 将命令行参数 (args[]) 解析为 int[][] 类型
- c# - 如何将 Office Addin 从非活动状态切换为活动状态?
- c++11 - VideoCapture(0) 和 VideoCapture.open(0) 似乎不适用于 CMake (UBUNTU) (OpenCV4)
- python - 如何从本地 python 脚本调用我的 AWS Lambda 函数?