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() {
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 );
You can’t perform that action at this time.
0 commit comments