Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions java/src/org/openqa/selenium/support/ui/Select.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,30 @@ public WebElement getFirstSelectedOption() {
@Override
public void selectByVisibleText(String text) {
assertSelectIsEnabled();
assertSelectIsVisible();

// try to find the option via XPATH ...
List<WebElement> options =
element.findElements(
By.xpath(".//option[normalize-space(.) = " + Quotes.escape(text) + "]"));

boolean selectedAnyVisible = false;

for (WebElement option : options) {
setSelected(option, true);
if (!isMultiple()) {
return;
if (hasCssPropertyAndVisible(option)) {
setSelected(option, true);
selectedAnyVisible = true;
if (!isMultiple()) {
return;
}
}
}

if (!selectedAnyVisible && !options.isEmpty()) {
// if we found options, but none of them was visible, we throw an exception
throw new NoSuchElementException("No visible option with text: " + text);
}

boolean matched = !options.isEmpty();
if (!matched && text.contains(" ")) {
String subStringWithoutSpace = getLongestSubstringWithoutSpace(text);
Expand Down
Loading