Selenium - 如何在页面上匹配图像的存在和位置 [英] Selenium - How to match image presence and location on page

查看:34
本文介绍了Selenium - 如何在页面上匹配图像的存在和位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的查询是 - 我在网页上有我的图像 - 一个徽标或说导航栏我可以存储为图像.当加载这些图像以及页面上图像的位置时,我可以使用 selenium 测试这些图像在网页上的存在吗?我的问题是我需要实际查看 HTML 中的图像对象,也可能不是 HTML 中的图像,但它们是我想要匹配的网页的部分屏幕截图.此测试将帮助我选择对齐问题 - 如果我的导航栏现在转到第二行,我可以与之前存储的图像进行匹配以进行检查.

My query is that - I have my images on webpage- a logo or say navigation bar i can store as an image. Can i test using selenium presence of these images on a webpage when loaded along with the position of the image on page. What my issue is that i need to actually look at image objects in HTML and also may be images not in HTML but they are partial screenshots of webpage which i want to match. This test will help me pick alignment issues - in case my navigation bar is now going to second row i can match with previous stored image to check.

谢谢VB

推荐答案

关于如何检查特定图像是否存在的示例:

An example on how to check if a particular image is present:

在此页面中:http://www.google.ie/firefox?client=firefox-a&rls=org.mozilla:en-US:official

Selenese 命令

Command: verifyElementPresent
Target: //td/table/tbody/tr/td/table/tbody/tr/td/img[@src='/images/firefox/Fx4Launch.png']

提示:如果您需要帮助获取特定元素的 XPath,我建议您使用 Firebug 之类的插件 (http://getfirebug.com/)

Hint: If you want help to get the XPath for a particular element I recommend you using a plugin like Firebug (http://getfirebug.com/)

在 Firebug 复制的 xpath 的开头多加一个\",否则 selenium 找不到元素.

Put an extra "\" in the beginning of the xpath copied by Firebug, otherwise selenium do not find the element.

这篇关于Selenium - 如何在页面上匹配图像的存在和位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆