0 votes
1 view
in Devops and Agile by (19.8k 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 (63.4k 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"));

        System.out.println(options);

        for (WebElement option : options)

        {

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

            {

                option.click(); // click the desired option

            }

        } 

Hope this helps!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...