Answer the question
In order to leave comments, you need to log in
How can I use WebElement.findElements(By.xpath .. to search only child nodes?
The webdriver loads a heavy page and, to optimize speed, I immediately look for an array of
List els = driver.findElements(By.xpath("parentLocator"));
More than a thousand nodes are successfully found (let's call them parent), each of which contains about a hundred child nodes that differ from each other within the same parent, but repeat as a template set from parent to parent. The essence of the question is how to force els.get(2).findElements(By.xpath("//*[@data-module='childComponent'")); do a search only on child elements, and not on the entire page, returning an array of a thousand elements (by the number of parents). Successfully tested a way to search by a locator of this kind
String locator = ".//*[@class='feed h-mod'][" + (ii+1)+
"]//*[@data-module='LikeComponent' and @data-type='RESHARE']//*[@class='widget_count js-count']";
WebElement themeLink = driver.findElement(By.xpath(locator));
But this method requires searching the entire page, and the larger the index ii, the slower it works. My logic tells me that somehow you can force els.get(2).findElements(By.xpath( to search only for child elements
Answer the question
In order to leave comments, you need to log in
search only child elements, not the entire page
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question