Selenium - How to match image presence and location on page

好久不见. 提交于 2019-12-23 03:46:11

问题


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.

Thanks VB


回答1:


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

In this page:http://www.google.ie/firefox?client=firefox-a&rls=org.mozilla:en-US:official

Selenese command

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

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

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




回答2:


You can verify that an image is at a location like so:

verifyElementPresent //div/p/img

This example uses XPath to locate an <img> element that follows a <div> and <p> tag.

But verifying that a screenshot is the same as the rendered page? You're talking about a completely different problem, which is image recognition. Selenium is a tool for automated acceptance testing.



来源:https://stackoverflow.com/questions/5587616/selenium-how-to-match-image-presence-and-location-on-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!