'Finding child element while having parent element

There is an element having various children. How can I count the number of its children using parents' xpath?

So far, I have been using this:

List<Webelement> myList = driver.findElements(By.parentXpath)

As it is obvious,the size of my list is always 1 cause there is only 1 parent element.



Solution 1:[1]

Having parent xpath you can follow the line bellow to get its child: List myList = driver.findElements(By.parentXpath/child::li/child::div) instead of just copy and paste the code try to substitute "div" and "lib" with the classes you really have.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 abbas