Skip to content

Commit

Permalink
Added helper methods for select lists
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Nov 5, 2020
1 parent 51ce106 commit b2fe607
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WrapsElement;
import org.openqa.selenium.interactions.Locatable;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.Wait;

import java.time.Duration;
import java.time.temporal.TemporalUnit;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@ImplementedBy(WebElementFacadeImpl.class)
public interface WebElementFacade extends WebElement, WrapsElement, WebElementState, Locatable, ConfigurableTimeouts, FindsByAccessibilityId, FindsByAndroidUIAutomator {
Expand Down Expand Up @@ -61,6 +63,12 @@ public interface WebElementFacade extends WebElement, WrapsElement, WebElementSt

List<String> getSelectOptions();

String getFirstSelectedOptionVisibleText();
List<String> getSelectedVisibleTexts();

String getFirstSelectedOptionValue();
List<String> getSelectedValues();

/**
* Type a value into a field, making sure that the field is empty first.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
import org.openqa.selenium.interactions.Coordinates;
import org.openqa.selenium.interactions.Locatable;
import org.openqa.selenium.support.pagefactory.ElementLocator;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Sleeper;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -932,6 +929,26 @@ public String getSelectedVisibleTextValue() {
return dropdownSelect().visibleTextValue();
}

@Override
public String getFirstSelectedOptionVisibleText() {
return new Select(this).getFirstSelectedOption().getText();
}

@Override
public List<String> getSelectedVisibleTexts() {
return new Select(this).getAllSelectedOptions().stream().map(WebElement::getText).collect(Collectors.toList());
}

@Override
public String getFirstSelectedOptionValue() {
return new Select(this).getFirstSelectedOption().getAttribute("value");
}

@Override
public List<String> getSelectedValues() {
return new Select(this).getAllSelectedOptions().stream().map(element -> element.getAttribute("value")).collect(Collectors.toList());
}

@Override
@Deprecated
public WebElementFacade selectByValue(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,26 @@ public List<String> getSelectOptions() {
return new ArrayList<>();
}

@Override
public String getFirstSelectedOptionVisibleText() {
return null;
}

@Override
public List<String> getSelectedVisibleTexts() {
return null;
}

@Override
public String getFirstSelectedOptionValue() {
return null;
}

@Override
public List<String> getSelectedValues() {
return null;
}

/**
* Check that an element contains a text value
*
Expand Down

0 comments on commit b2fe607

Please sign in to comment.