Skip to content

Commit 067adce

Browse files
feat(java): handle invisible options gracefully in selectByVisibleText
Refactored the logic in selectByVisibleText to skip invisible options instead of failing fast. The method now continues evaluating other options with matching visible text, ensuring consistent behavior when multiple matching elements exist but some are hidden via CSS. This change improves robustness and aligns with cross-language expectations for Select component behavior. Relates to #15265
1 parent b17b013 commit 067adce

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,13 @@ public void selectByVisibleText(String text) {
133133
boolean selectedAnyVisible = false;
134134

135135
for (WebElement option : options) {
136-
if (!hasCssPropertyAndVisible(option)) {
137-
throw new NoSuchElementException("Invisible option with text: " + text);
138-
}
139-
setSelected(option, true);
140-
if (!isMultiple()) {
141-
return;
136+
if (hasCssPropertyAndVisible(option)) {
137+
// throw new NoSuchElementException("Invisible option with text: " + text);
138+
setSelected(option, true);
139+
selectedAnyVisible = true;
140+
if (!isMultiple()) {
141+
return;
142+
}
142143
}
143144
}
144145

0 commit comments

Comments
 (0)