gpt4 book ai didi

xpath - 如何使用 XPath 查询在 SVG 图像内通过其 href 查找图像?

转载 作者:行者123 更新时间:2023-12-03 00:54:30 24 4
gpt4 key购买 nike

我有一个包含“div”元素的网站。在这个“div”内部,存在一个“svg”元素,它是由 JavaScript 库“RaphaelJS”生成的。此外,我已指示 RaphaelJS 在 SVG 元素内创建具有特定 href 的图像。

为了进行一些 GUI 测试,我想测试图像是否确实存在于 SVG 元素内,并具有预期的 href。现在我想编写一个 XPath 查询(如果可能的话稍后在 Selenium IDE 中使用)来进行测试。我似乎无法使用 XPather 或 Selenium IDE 完成工作。

网站正文简而言之如下:

<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
...
<body>
...
<div id="my-container">
<table id="my-table">
<tbody>
<tr>
<td>
<div id="my-raphael-canvas">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100">
<image x="0" y="0" width="10" height="10" preserveAspectRatio="none" href="/images/my-icon.jpg"/>
</svg>
</div>
</td>
</tr>
</tbody>
</table>
...
</body>
</html>

如果我想通过“href”找到“image”元素(在 svg 内),XPath 查询应该是什么样子?

预先感谢您的帮助!

最佳答案

boolean(//xhtml:div[@id = 'my-raphael-canvas']/svg:svg/svg:image[@xlink:href = '/images/my-icon.jpg'])您需要确保前缀 xhtml绑定(bind)到 XHTML 命名空间 http://www.w3.org/1999/xhtml ,前缀svg到 SVG 命名空间 http://www.w3.org/2000/svg ,以及前缀 xlink到 XLink 命名空间 http://www.w3.org/1999/xlink

实际上您发布的示例有 href SVG 的属性 image没有命名空间的元素,但据我所知,SVG 定义了 xlink:hrefimage 上的属性元素,因此我编写的路径使用了它。

关于xpath - 如何使用 XPath 查询在 SVG 图像内通过其 href 查找图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6386827/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com