在 Selenium 中通过 src 搜索图像

发布于 2024-09-16 13:42:33 字数 308 浏览 4 评论 0原文

我必须编写一个 Selenium 测试,并且需要通过 src 获取一个元素,因为它没有 ID。

我该如何做类似 //div[@id='content-inner'] 但使用 @src='../mapshop/images/buy.png' 或者使用包含“buy.png”更好?

我尝试测试图像是否存在,但是 selenium.IsElementPresent("//img [@src='../mapshop/images/buy.png']") 但这只是返回错误的。

I have to write a Selenium test and I need to get an element by the src as there is no ID for it.

How do I go about doing something like //div[@id='content-inner'] but with @src='../mapshop/images/buy.png' or even better using a contains 'buy.png'?

I've tried testing if the image is there but, selenium.IsElementPresent("//img [@src='../mapshop/images/buy.png']") but that just returns false.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住你手 2024-09-23 13:42:34

发现问题了。

很简单。需要指定完整的图像 url 而不仅仅是 src

selenium.IsElementPresent("//img [@src='http://dev.emapsite.com/QA/mapshop/images/edit.png']")  
returns true.

Found the problem.

Very simple. Needed to specify the full image url not just the src

selenium.IsElementPresent("//img [@src='http://dev.emapsite.com/QA/mapshop/images/edit.png']")  
returns true.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文