Reputation: 337
I asked this question but needed help again. I'm trying to get all image src in the page to check if there is not loaded image in the page. I used these codes but it takes all images src's .How can I take only these srcs in "butik-large-image" class.
Here are my codes:
List<WebElement> srcClass;
String [] cats={"TÜM BUTİKLER","KADIN","ERKEK","ÇOCUK","SPOR GİYİM","AYAKKABI & ÇANTA","SAAT & "
+ "AKSESUAR","KOZMETİK","EV & YAŞAM","HIZLI TESLİMAT"};
for (String kat : cats) {
sleep(1000);
clickObjectByLinkText(kat);
srcClass = driver.findElements(By.tagName("img"));
System.out.println(kat +" için image src linkleri");
for (WebElement src : srcClass){
if(src.getAttribute("src").equals(null))
System.out.println("Ekranda "+kat+" " + " kategorisi için image yüklenemeyen data bulundu,lütfen aşagıdaki pathleri inceleyiniz..");
System.out.println(src.getAttribute("src"));
}
System.out.println("---------------------------------------------------------------------------------------");
srcClass.clear();
}
My html source:
<div class="butik-large-image">
<a href="/Olgun-Orkun-x-Deniz-Akkaya-nin-Sectikleriyle---Kadin-Tekstil/ButikDetay/174246/Kadin" style="font-size: 0"
title="Olgun Orkun x Deniz Akkaya'nın Seçtikleriyle - Kadın Tekstil"
class="butik-img-size">
<img class="bigBoutiqueImage lazy-load-trigger loaded"
**src="https://img-trendyol.mncdn.com//Assets/ProductImages/OA/CampaignVisual/OriginalBoutiqueImages/13520/llardau3_0_new.jpg**" data-original="https://img-trendyol.mncdn.com//Assets/ProductImages/OA/CampaignVisual/OriginalBoutiqueImages/13520/llardau3_0_new.jpg" title="Olgun Orkun x Deniz Akkaya'nın Seçtikleriyle - Kadın Tekstil" onerror="this.src='/Resources/images/bigBoutiquePlaceHolder.png'" alt="Olgun Orkun x Deniz Akkaya'nın Seçtikleriyle - Kadın Tekstil">
<div class="efect">
</div>
</a>
</div>
Upvotes: 1
Views: 213
Reputation: 1165
Idea is :
The complete implementation for your desired requirement is below:
List<WebElement> allImagesUnderThisClass = driver.findElements(By.className("butik-large-image"));
String ignoreImageURl = "https://www.trendyol.com/Resources/images/bigBoutiquePlaceHolder.png";
for(WebElement elem : allImagesUnderThisClass){
List<WebElement> imgs = elem.findElements(By.tagName("img"));
for(WebElement img : imgs){
String source = img.getAttribute("src");
if(!source.equalsIgnoreCase(ignoreImageURl)){
System.out.println(source);
}
}
}
Upvotes: 1
Reputation: 50809
You can look for <img>
tag under an element with butik-large-image
class
srcClass = driver.findElements(By.cssSelector(".butik-large-image img"));
The space between the class and tag means any descendant.
Upvotes: 0