File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed
java/src/org/openqa/selenium/support/ui Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -124,11 +124,14 @@ public WebElement getFirstSelectedOption() {
124
124
public void selectByVisibleText (String text ) {
125
125
assertSelectIsEnabled ();
126
126
assertSelectIsVisible ();
127
+
127
128
// try to find the option via XPATH ...
128
129
List <WebElement > options =
129
130
element .findElements (
130
131
By .xpath (".//option[normalize-space(.) = " + Quotes .escape (text ) + "]" ));
131
132
133
+ boolean selectedAnyVisible = false ;
134
+
132
135
for (WebElement option : options ) {
133
136
if (!hasCssPropertyAndVisible (option )) {
134
137
throw new NoSuchElementException ("Invisible option with text: " + text );
@@ -139,6 +142,11 @@ public void selectByVisibleText(String text) {
139
142
}
140
143
}
141
144
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
+
142
150
boolean matched = !options .isEmpty ();
143
151
if (!matched && text .contains (" " )) {
144
152
String subStringWithoutSpace = getLongestSubstringWithoutSpace (text );
You can’t perform that action at this time.
0 commit comments