If I have a structure like the one below, I am looking to access each individual div inside its parent div and print its id using a for loop.
<div class=abc>
<div id="parent">
<div id="one">
<div id=........</div>
<div id=........</div>
<div id="two">
<div id=........</div>
<div id=........</div>
<div id="three">
<div id=........</div>
<div id=........</div>
<div id="four">
<div id=........</div>
<div id=........</div>
<div id="five">
<div id=........</div>
<div id=........</div>
<div id="six">
<div id=........</div>
<div id=........</div>
<div id="seven">
<div id=........</div>
<div id=........</div>
<div id="eight">
<div id=........</div>
<div id=........</div>
</div>
</div>
When trying to print (in Java), all nested div ids are also being printed. How can I retrieve only the ids of the eight main divs in one for-loop? I am automating a website using Selenium WebDriver and have attempted the following:
List<WebElement> eightDivs = driver.findElements(By.cssSelector("#abc div:nth-child(n)"));
for(WebElement singleDiv : eightDivs)
{
System.out.println(singleDiv.getAttribute("id"));
}