net.thucydides.core.webelements.MultipleSelect Maven / Gradle / Ivy
package net.thucydides.core.webelements;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* A convenience class to help handle multiple select fields.
*/
public class MultipleSelect {
private final WebElement dropdownField;
public MultipleSelect(final WebElement dropdownField) {
this.dropdownField = dropdownField;
}
public Set getSelectedOptionLabels() {
List options = new Select(dropdownField).getAllSelectedOptions();
Set selectedOptions = new HashSet<>();
for (WebElement option : options) {
if (option.isSelected()) {
selectedOptions.add(option.getText());
}
}
return selectedOptions;
}
public Set getSelectedOptionValues() {
Set selectedOptions = new HashSet();
List options = dropdownField.findElements(By.tagName("option"));
for (WebElement option : options) {
if (option.isSelected()) {
selectedOptions.add(option.getAttribute("value"));
}
}
return selectedOptions;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy