简体   繁体   English

使用Selenium WebDriver验证网页上的图像

[英]Validating image on a webpage using selenium webdriver

I am trying to write a code to visit on each product on a product listing page and extract information. 我正在尝试编写代码以访问产品列表页面上的每个产品并提取信息。 Can anyone suggest me the logic and code so that I can move ahead in my project? 谁能建议我一些逻辑和代码,以便我可以继续进行自己的项目?

Code when image is available: 图片可用时的代码:

<img class="btn zoom" src="http://asset1.marksandspencer.com/is/image/mands/RC_01_T62_9451K_H4_X_EC_90?$PDP_PROD_IMAGE$" data-image-set-count="3" data-caro-slide-rel="1">

Code when images is not available: 图片不可用时的代码:

<img class="btn zoom" src="http://asset1.marksandspencer.com/is/image/?$PDP_PROD_IMAGE$" data-image-set-count="1" data-caro-slide-rel="1">

Not sure on your query but you if you want to find the List of Images present , Images Loaded vs not Loaded . 不确定查询的内容,但是如果要查找当前的图像列表,即已加载图像和未加载图像。

All Images can be captured in the Section using driver.findElements ( By.tag using "img". This will return the List of all section if image in specific section. Good not to try on complete page or on driver as you may find more image link tag. 可以使用driver.findElements(使用“ img”的By.tag捕获该部分中的所有图像。如果特定部分中的图像,这将返回所有部分的列表。请不要尝试在整个页面或驱动程序上尝试,因为您可能会发现更多内容图片链接标记。

So first identify the section t test , then get the WebElement of the section from the driver . 因此,首先确定t测试部分,然后从驱动程序获取该部分的WebElement。 Then use the above way to find ALL image List 然后使用上面的方法找到所有图片列表

Now to find the Loaded and not loaded list : 现在找到“已加载但未加载”列表:

When Image NOT Loaded your source ( src) contains 当未加载图片时,您的源(src)包含

is/image/?$PDP_PROD_IMAGE$" 是/图片/?$ PDP_PROD_IMAGE $”

When Image available and loaded your source ( src)contains 当可用映像并加载了源(src)时

is/image/mands/RC_01_T62_9451K_H.......... 是/ image / mands / RC_01_T62_9451K_H ..........

So write a xpath or css Regular expression which can list you the loaded and not loaded image by comparing your src parameter 因此,编写一个xpath或CSS正则表达式,可以通过比较src参数来列出已加载和未加载的图像

Equals to "src="http://asset1.marksandspencer.com/is/image/mands/RC_01_T62_9451K_H4_X_EC_90?$PDP_PROD_IMAGE$"" => Not Loaded Image 等于 “ src =“ http://asset1.marksandspencer.com/is/image/mands/RC_01_T62_9451K_H4_X_EC_90?$PDP_PROD_IMAGE$”“” =>未加载图像

Not equals to src="http://asset1.marksandspencer.com/is/image/mands/RC_01_T62_9451K_H4_X_EC_90?$PDP_PROD_IMAGE$"" => Loaded Image 等于src =“ http://asset1.marksandspencer.com/is/image/mands/RC_01_T62_9451K_H4_X_EC_90?$PDP_PROD_IMAGE$”“ =>已加载图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM