Search code examples
javaselenium-webdriverselenide

Find all Child Elements of an Selenide Element


I have an element on my webpage which I call base element. I'm looking for all children with a certain tag of base. In pure Selenium & Java I would do something like:

WebElement base = driver.findElement(...);
List<WebElement> children = base.findElements(By.tagName("button"));

How can I do this in Selenide?


Solution

  • In selenide, you can $$ to get child elements from the parent element.

    SelenideElement base = $(.....);
    
    //if you want to use the class name
    ElementsCollection children = base.$$('child className');
    
    //if you want to use tagName then
    ElementsCollection children = base.$$(By.tagName('child tagname'));