praj
praj

Reputation: 859

selenide code for how to fetch dropdown list value?

i am trying to fetch all values from dropdown list using selenide . using selectOptionByValue("0") i can fetch one value. But i need all values inside dropdown list. Let me know how to do this using selenide code

Upvotes: 0

Views: 2187

Answers (3)

Michael Dally
Michael Dally

Reputation: 194

You could use ElementsCollection:

ElementsCollection listOfElements = $$(By.cssSelector(".its_a_spicy_meatball"));

Note the two $ symbols - this denotes an the object as an ElementCollection

Example:

for(SelenideElement element : listOfElements){
    element.click();
}

Upvotes: 0

Konstantin Firsanov
Konstantin Firsanov

Reputation: 64

Try this solution:

Select select = new Select($(By.id("<SELECT_ID>")));
List<WebElement> elements = select.getOptions();

Upvotes: 0

Ivan
Ivan

Reputation: 11

Maybe, you could try to use something like this:

$$(By.xpath("//path/to/element")).iterator().forEachRemaining(element -> {
    /**
    * your code here, describe here what to do with each element found by the xpath 
    * e.x. 
    * element.click();
    */
});

I used it to click through all links on the page with specific class attribute.

Upvotes: 1

Related Questions