我有一个图像列表,每个都需要点击。 以下是 HTML
<div id="VELayerListDiv">
<div id="msftve_1002">
<a id="msftve_1002_200000_10000" class="VEAPI_Pushpin" href="javascript://pushin hover" style="position: absolute; left: -17px; top: 450px; display: block; z-index: 1000;">
<div onmousedown="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmousedown"))return;VEDragVEShapeDown("msftve_1002_200000_10000",1429800443062);" onmouseover="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmouseover"))return;VEShowVEShapeERO("msftve_1002_200000_10000",1429800443062);" onmouseout="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmouseout"))return;VEHideVEShapeERO(false);">
<div style="position:absolute;left:6.5px;top:-2px;writing-mode:tb-rl;filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=0, xray=0, mirror=0, invert=0, opacity=1, rotation=0);opacity:1;">
<img width="17" height="34" src="images/spatial/custout_50-499_U2.png"/>
</div>
</div>
</a>
</div>
<div id="msftve_1003">
<a id="msftve_1003_200003_10003" class="VEAPI_Pushpin" href="javascript://pushin hover" style="position: absolute; left: 278.5px; top: 363.5px; display: block; z-index: 1000;">
<div onmousedown="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmousedown"))return;VEDragVEShapeDown("msftve_1003_200003_10003",1429800443062);" onmouseover="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmouseover"))return;VEShowVEShapeERO("msftve_1003_200003_10003",1429800443062);" onmouseout="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmouseout"))return;VEHideVEShapeERO(false);">
<div style="position:absolute;left:6.5px;top:-2px;writing-mode:tb-rl;filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=0, xray=0, mirror=0, invert=0, opacity=1, rotation=0);opacity:1;">
<img width="17" height="34" src="images/spatial/custout_2-49_U2.png"/>
</div>
</div>
</a>
<a id="msftve_1003_200004_10004" class="VEAPI_Pushpin" href="javascript://pushin hover" style="position: absolute; left: 277.5px; top: 362.5px; display: block; z-index: 1000;">
<div onmousedown="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmousedown"))return;VEDragVEShapeDown("msftve_1003_200004_10004",1429800443062);" onmouseover="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmouseover"))return;VEShowVEShapeERO("msftve_1003_200004_10004",1429800443062);" onmouseout="if (VEMap._GetMapFromGUID(1429800443062).FireEvent("onmouseout"))return;VEHideVEShapeERO(false);">
<div style="position:absolute;left:6.5px;top:-2px;writing-mode:tb-rl;filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=0, xray=0, mirror=0, invert=0, opacity=1, rotation=0);opacity:1;">
<img width="17" height="34" src="images/spatial/custout_2-49_U2.png"/>
</div>
</div>
</a>
</div>
我写了以下代码:
List<WebElement> pins = driver.findElements(By.xpath("//*[@id='VELayerListDiv']/div/a/div/div/img")));
System.out.println("Total Pins :"+pins.size());
for(int x=0;x<pins.size();x++)
{
pins.get(x).click();
}
以上代码随机点击引脚。它没有唯一地点击所有的Pins(即所有imgs)。我点击了img1,img2,img1,img3,img1
我不知道出了什么问题,因为我在列表中得到了所有的img(因为pins.size()
是正确的)。但是点击不会单独点击每个img。
这与img
标记没有任何唯一标识符有关。