Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

There is this element that has child elements, those child elements again have child elements and so on. I would like to get all the elements that are descendants of the element. Thanks.

1 Answer

0 votes
by (62.9k points)

You can try the below code, instead of using XPath since it will be useful in dynamic variables also.

         String searchText = "your element's text";

        WebElement dropdown = driver("parent locator").findElement(By.tagName("ul"));

        List<WebElement> options = dropdown.findElements(By.tagName("li"));


        for (WebElement option : options)


            if (option.getText().equals(searchText))


      ; // click the desired option



Hope this helps!

Browse Categories