如何使用带有 Java 的 WebDriver 创建 "background-image" CSS 的列表

How to make a list of "background-image" CSS using WebDriver with Java

我正在尝试列出所有 background-image 值,以便我可以断言它们。

我正在制作一个 parent,然后我试图获取所有值的列表。

这是我目前拥有的:

WebElement Assert_Parent = driver.findElement(By.xpath("/html/body/div[1]/section/div[1]/div[2]/div"));  
List<WebElement> Assert_children = Assert_Parent.findElements(By.cssSelector("div.contentInner[name='background-image']"));  
System.out.print(Assert_children);

在每张照片下面,这里是一张特定的照片html,也许我指错了,或者试图做错了。

<div id="contentInner" class="contentInner" style="background-color: transparent;">
<div class="picturearea content maxclass_15">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
   <div class="photo">
      <a class="btnShowPhoto" target="_blank" ng-click="showPhoto(photo, $index+1)">
      <i class="uiMediaThumbImg" ng-style="{'background-image':'url(http://images.myphototab.com/pop%20art/pa64172136-206.jpg)'}" style="background-image: url("http://images.myphototab.com/pop%20art/pa64172136-206.jpg"); border-color: rgb(0, 128, 191);"></i>
      </a>
   </div>
</div>
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
   <div class="photo">
      <a class="btnShowPhoto" target="_blank" ng-click="showPhoto(photo, $index+1)">
      <i class="uiMediaThumbImg" ng-style="{'background-image':'url(http://images.myphototab.com/space/sp52774334-206.jpg)'}" style="background-image: url("http://images.myphototab.com/space/sp52774334-206.jpg"); border-color: rgb(0, 128, 191); background-color: transparent;"></i>
      </a>
   </div>
</div>
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit">
<div class="photos" style="margin: 12.78px;" ng-repeat="photo in photos | limitTo:photos.limit"></div>

如有任何建议,我们将不胜感激。

//partial css search with "*"
By regExCss = By.cssSelector("[ng-style*='background-image']");

List<WebElement> children = driver.findElements(regExCss);  
// And if you want to print every child(possibly some attribute)
// do a loop

int count = children.size();

for(int i= 0; i<count; i++){
    System.out.print(children.get(i).getAttribute("Class") + "\n");
}