io.github.kgress.scaffold.webelements.DropDownWebElement Maven / Gradle / Ivy
package io.github.kgress.scaffold.webelements;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import java.util.List;
import java.util.stream.Collectors;
/**
* A strongly typed representation of a DropDown {@link WebElement}.
*/
public class DropDownWebElement extends AbstractWebElement {
public DropDownWebElement(By by) {
super(by);
}
public DropDownWebElement(By by, By parentBy) {
super(by, parentBy);
}
public DropDownWebElement(By by, WebElement parentElement) {
super(by, parentElement);
}
public DropDownWebElement(WebElement element) {
super(element);
}
/**
* Returns a list of options in the DropDown
*
* @return the list of options.
*/
public List getOptionsText() {
return getSelectElement().getOptions().stream()
.map(WebElement::getText)
.collect(Collectors.toList());
}
/**
* @param index the index to select
* @see Select#selectByIndex(int)
*/
public void selectByIndex(int index) {
getSelectElement().selectByIndex(index);
}
/**
* @param value the value to select
* @see Select#selectByIndex(int)
*/
public void selectByValue(String value) {
getSelectElement().selectByValue(value);
}
public void getValue() {
getWebElement().getAttribute("value");
}
/**
* Sets the drop-down to the value contained in the visible of the {@literal
© 2015 - 2025 Weber Informatics LLC | Privacy Policy