0

I'm so new in Selenium need help. I'm trying to get all image src in the page to check if there is not loaded image in the page. How can I check the images src? Can I check with "null"? Here is my code and of course there are mistakes. Also I checked some links for this issue, but didn't solve my problems for example this link: Selenium: How do I get the src of an image?

Do you know docs for the selenium selectors for learning?

  List<String>srcLinks = null;  
    List<WebElement> srcClass=driver.findElements(By.tagName("img"));
       for (WebElement src : srcClass) {
              srcLinks.add(src.getAttribute("src"));
               System.out.println(src);
           }
          for(int i=0;i<srcLinks.size();i++) {
              if(srcLinks.get(i).contains(null)) {
                  System.out.println("null img src found");
              }
      }

Also here is the HTML code for src:

<img class="bigBoutiqueImage lazy-load-trigger loaded"
 **src="https://img-trendyol.mncdn.com//Assets/ProductImages/OA/CampaignVisual/OriginalBoutiqueImages/12640/4pu3yjc3_11_new.jpg"** 
data-original="https://img-trendyol.mncdn.com//Assets/ProductImages/OA/CampaignVisual/OriginalBoutiqueImages/12640/4pu3yjc3_11_new.jpg" 
title="Twigy - Yılbaşı Özel"
 onerror="this.src='/Resources/images/bigBoutiquePlaceHolder.png'" 
alt="Twigy - Yılbaşı Özel">
gre_gor
  • 6,669
  • 9
  • 47
  • 52
laura
  • 357
  • 3
  • 16

1 Answers1

1

To print the src attributes of the images you can use the following code block :

List<WebElement> srcClass = driver.findElements(By.tagName("img"));
for (WebElement src : srcClass)
    System.out.println(src.getAttribute("src"));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352