要素のリストから子要素を取得しようとしましたが、リスト内の各項目の子要素の値を返す代わりに、最初の項目のみを返します。
List<WebElement> allAccoElements = driver.findElements(By.xpath("//ul[@id='ListerContainer']//li[@class='lister-item']//div[@class='lister-item-content']"));
// Found 10 items
for (WebElement element: allAccoElements){
System.out.println(element.findElement(By.xpath("//img[@class='image-base']")).getAttribute("id"));
//For loop will print "id" of first element 10 times, why I can't to get access to other Elements in list?
}
Print always return id of first element in list, can anyone suggest me, how I can find child element of each element in list?
代わりに、回避策のような次のコードを使用すると、すべて正常に動作します。
List<WebElement> allAccoElements = driver.findElements(By.xpath("//ul[@id='ListerContainer']//li[@class='lister-item']//div[@class='lister-item-content']//img[@class='image-base']"));
// Found 10 items:
for (WebElement element: allAccoElements){
System.out.println(element.getAttribute("id"));
//Print 10 times with different id
}