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.

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
Elsid
  • 243
  • 2
  • 10
  • 25

1 Answers1

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");
}
Saifur
  • 16,081
  • 6
  • 49
  • 73
  • System.out.printin(children.get(i).getAttribute('class')); this isn't working telling me invalid character constant. – Elsid Apr 08 '15 at 15:05
  • @Elsid sorry little typo. Try it now – Saifur Apr 08 '15 at 16:21
  • still the same the system.out gives me invalid won't let me write it. – Elsid Apr 08 '15 at 20:02
  • @Elsid It was a syntax error. I used single quote (') instead of double quote ("). Just tested and it should work now – Saifur Apr 09 '15 at 01:24
  • Hi throwing this error now: The method count() is undefined for the type List – Elsid Apr 09 '15 at 17:12
  • See my edit. there was another edit. I was mixing C# and Java – Saifur Apr 09 '15 at 17:17
  • 1
    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 – Elsid Apr 09 '15 at 18:43
  • 1
    fixed i changed get.Attribute to "style" instead of class. Thanks – Elsid Apr 09 '15 at 18:55
  • Hi Saifur, how would i be able to assert that "xyz text" is contained in it, I just realized that it is a list and not a string. Thanks – Elsid Apr 09 '15 at 19:13
  • Are you using TestNg? – Saifur Apr 09 '15 at 19:17
  • yes, I am using this code Assert.assertTrue(Assert_Picture.contains("background") ? true : Assert_Picture.contains("ancient%20ruins") ect. ect. – Elsid Apr 09 '15 at 19:18
  • You want to make sure all the elements has something matching? – Saifur Apr 09 '15 at 19:28
  • not all of them, but in that list I want to make sure the word "background" is contained or "ancient%20ruins" is contained anywhere in the list for any element. – Elsid Apr 09 '15 at 19:30
  • See [this](http://stackoverflow.com/questions/12166415/how-do-i-assert-a-list-contains-elements-with-a-certain-property) answer – Saifur Apr 09 '15 at 19:34
  • yeah tried assertThat doesn't seem to really work with TestNG. I imported everything but still a bit weird. It's ok i'll mess around with it i'll figure something out. – Elsid Apr 09 '15 at 20:26
  • I will try it when I get back home. I do not have a set up to test against TestNg at my office – Saifur Apr 09 '15 at 20:27