1

I'm trying to make a list of all the background-image values so i could assert them all.

I am making a parent, and then I am trying to get a list of all the values.

This is what i have so far:

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);

Under each photos, is a specific photo here is the html, maybe i am pointing to it wrong, or trying to go about it wrong.

<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>

Any suggestions would be appreciated.

2
  • Is the html relevant? Commented Apr 7, 2015 at 20:28
  • yes as i need to store all the ng-style background-images values. Commented Apr 8, 2015 at 13:45

1 Answer 1

1
//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");
}
Sign up to request clarification or add additional context in comments.

16 Comments

System.out.printin(children.get(i).getAttribute('class')); this isn't working telling me invalid character constant.
@Elsid sorry little typo. Try it now
still the same the system.out gives me invalid won't let me write it.
it works, but the only issue is it returns only uimediathumbimg how can i make it point to make it return all the urls? thanks
fixed i changed get.Attribute to "style" instead of class. Thanks
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.