Skip to content

Commit 61d125b

Browse files
fix: continue searching for visible optiones before throwing in selectByVisibleText
1 parent 5d9b5d1 commit 61d125b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

java/src/org/openqa/selenium/support/ui/Select.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ public WebElement getFirstSelectedOption() {
124124
public void selectByVisibleText(String text) {
125125
assertSelectIsEnabled();
126126
assertSelectIsVisible();
127+
127128
// try to find the option via XPATH ...
128129
List<WebElement> options =
129130
element.findElements(
130131
By.xpath(".//option[normalize-space(.) = " + Quotes.escape(text) + "]"));
131132

133+
boolean selectedAnyVisible = false;
134+
132135
for (WebElement option : options) {
133136
if (!hasCssPropertyAndVisible(option)) {
134137
throw new NoSuchElementException("Invisible option with text: " + text);
@@ -139,6 +142,11 @@ public void selectByVisibleText(String text) {
139142
}
140143
}
141144

145+
if (!selectedAnyVisible && !options.isEmpty()) {
146+
// if we found options, but none of them was visible, we throw an exception
147+
throw new NoSuchElementException("No visible option with text: " + text);
148+
}
149+
142150
boolean matched = !options.isEmpty();
143151
if (!matched && text.contains(" ")) {
144152
String subStringWithoutSpace = getLongestSubstringWithoutSpace(text);

0 commit comments

Comments
 (0)