D
D
densaface2016-02-29 15:07:31
Java
densaface, 2016-02-29 15:07:31

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

1 answer(s)
A
Alexey Sundukov, 2016-02-29
@densaface

search only child elements, not the entire page

Add an axis of work with descendants.
Although the description is not very clear which elements are parent and which are child. What is the structure of the parent-child subtree?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question