@@ -43,6 +43,13 @@ public void shouldThrowAnExceptionIfTheElementIsNotASelectElement() {
4343 .isThrownBy (() -> new Select (selectElement ));
4444 }
4545
46+ @ Test
47+ public void shouldThrowAnExceptionIfTheElementIsDisabled () {
48+ WebElement selectElement = driver .findElement (By .name ("no-select" ));
49+ assertThatExceptionOfType (UnsupportedOperationException .class )
50+ .isThrownBy (() -> new Select (selectElement ));
51+ }
52+
4653 @ Test
4754 public void shouldIndicateThatASelectCanSupportMultipleOptions () {
4855 WebElement selectElement = driver .findElement (By .name ("multi" ));
@@ -85,7 +92,6 @@ public void shouldReturnAllOptionsWhenAsked() {
8592
8693 assertThat (select .getOptions ()).extracting (WebElement ::getText )
8794 .containsExactly ("One" , "Two" , "Four" , "Still learning how to count, apparently" );
88-
8995 }
9096
9197 @ Test
@@ -149,7 +155,16 @@ public void shouldThrowExceptionOnSelectByVisibleTextIfOptionDoesNotExist() {
149155 Select select = new Select (selectElement );
150156
151157 assertThatExceptionOfType (NoSuchElementException .class )
152- .isThrownBy (() -> select .selectByVisibleText ("not there" ));
158+ .isThrownBy (() -> select .selectByVisibleText ("not there" ));
159+ }
160+
161+ @ Test
162+ public void shouldThrowExceptionOnSelectByVisibleTextIfOptionDisabled () {
163+ WebElement selectElement = driver .findElement (By .name ("single_disabled" ));
164+ Select select = new Select (selectElement );
165+
166+ assertThatExceptionOfType (UnsupportedOperationException .class )
167+ .isThrownBy (() -> select .selectByVisibleText ("Disabled" ));
153168 }
154169
155170 @ Test
@@ -170,6 +185,15 @@ public void shouldThrowExceptionOnSelectByIndexIfOptionDoesNotExist() {
170185 .isThrownBy (() -> select .selectByIndex (10 ));
171186 }
172187
188+ @ Test
189+ public void shouldThrowExceptionOnSelectByIndexIfOptionDisabled () {
190+ WebElement selectElement = driver .findElement (By .name ("single_disabled" ));
191+ Select select = new Select (selectElement );
192+
193+ assertThatExceptionOfType (UnsupportedOperationException .class )
194+ .isThrownBy (() -> select .selectByIndex (1 ));
195+ }
196+
173197 @ Test
174198 public void shouldAllowOptionsToBeSelectedByReturnedValue () {
175199 WebElement selectElement = driver .findElement (By .name ("select_empty_multiple" ));
@@ -188,6 +212,15 @@ public void shouldThrowExceptionOnSelectByReturnedValueIfOptionDoesNotExist() {
188212 .isThrownBy (() -> select .selectByValue ("not there" ));
189213 }
190214
215+ @ Test
216+ public void shouldThrowExceptionOnSelectByReturnedValueIfOptionDisabled () {
217+ WebElement selectElement = driver .findElement (By .name ("single_disabled" ));
218+ Select select = new Select (selectElement );
219+
220+ assertThatExceptionOfType (UnsupportedOperationException .class )
221+ .isThrownBy (() -> select .selectByValue ("disabled" ));
222+ }
223+
191224 @ Test
192225 public void shouldAllowUserToDeselectAllWhenSelectSupportsMultipleSelections () {
193226 WebElement selectElement = driver .findElement (By .name ("multi" ));
0 commit comments