this is a simplified HTML structure i'm searching through:
<div class="main">
...other stuff...
<td class="child">44</td>
<td class="child">59</td>
<td class="child">11</td>
</div>
<div class="main">
...other stuff...
<td class="child">5</td>
<td class="child">14</td>
<td class="child">98</td>
</div>
...this kind of structure repeats with similar numbers a few more times but with identical class names
I need to extract all the numbers under the first found main class so I've made a query to search for the first main, and all td's with the specific class under it. Can somebody give me a hint what I'm doing wrong since this query gives me all the numbers from all td's with class "child" in all "main" div's:
List<WebElement> koefi = driver.findElements(By.xpath("//div[@class='main'][1]//td[@class='child']"));
What am I doing wrong or is my logic right but I'm missing some other parts of html which I haven't pasted here since the structure is too cumbersome..?
Thank You!!
p.s.: I tried this also but again, I get contents of all td's with "child" class, and not only the first "main"..
List<WebElement> koefi = driver.findElements(By.xpath("//*[1][@class='main']//td[@class='child']"));
UPDATE: I managed to solve my problem by first getting the first occurence of the "main" div which is by default found by the .findElement function:
WebElement element = driver.findElement(By.xpath("//*[1][@id='main']"));
And then extracting with .findElements function the "child" classes:
List<WebElement> kk = element.findElements(By.className("child"));
I am still unable to figure out why doesn't the .findElements with my xpath work, or it works too well, it extracts every "main" class and not only the first one. And the original HTML is too big to paste here, so I don't want to bother you guys!!
<div class="main">are siblings?//div[@class='main'][1]//td[@class='child']contains a relative path which holds true for all your main classes.