In this Selenide tutorial series post, we will learn how to work with multiple elements using the
$$ (css selector)
When working with individual element in Selenide, we use
$ sign which returns us a single element back. To work with multiple elements we need to use
$$ sign to get Elements Collection returned. Let’s take a look at an example –
ElementsCollection linkLists = $$("#primary-menu li[id*=menu-item]");
The above code will return all the elements matching the css selector as a collection of elements. You can then use this to iterate through the elements or get the text and so on..
$$ uses a css selector but you do have an option to provide any other selector as well such as XPath, name etc..
ElementsCollection linkLists = $$(By.xpath("//li[starts-with(@id, \"menu-item\")]"));
To learn more about working with multiple elements in Selenide, check out the video below –
Thanks for reading!