@@ -43,6 +43,13 @@ public void shouldThrowAnExceptionIfTheElementIsNotASelectElement() {
43
43
.isThrownBy (() -> new Select (selectElement ));
44
44
}
45
45
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
+
46
53
@ Test
47
54
public void shouldIndicateThatASelectCanSupportMultipleOptions () {
48
55
WebElement selectElement = driver .findElement (By .name ("multi" ));
@@ -85,7 +92,6 @@ public void shouldReturnAllOptionsWhenAsked() {
85
92
86
93
assertThat (select .getOptions ()).extracting (WebElement ::getText )
87
94
.containsExactly ("One" , "Two" , "Four" , "Still learning how to count, apparently" );
88
-
89
95
}
90
96
91
97
@ Test
@@ -149,7 +155,16 @@ public void shouldThrowExceptionOnSelectByVisibleTextIfOptionDoesNotExist() {
149
155
Select select = new Select (selectElement );
150
156
151
157
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" ));
153
168
}
154
169
155
170
@ Test
@@ -170,6 +185,15 @@ public void shouldThrowExceptionOnSelectByIndexIfOptionDoesNotExist() {
170
185
.isThrownBy (() -> select .selectByIndex (10 ));
171
186
}
172
187
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
+
173
197
@ Test
174
198
public void shouldAllowOptionsToBeSelectedByReturnedValue () {
175
199
WebElement selectElement = driver .findElement (By .name ("select_empty_multiple" ));
@@ -188,6 +212,15 @@ public void shouldThrowExceptionOnSelectByReturnedValueIfOptionDoesNotExist() {
188
212
.isThrownBy (() -> select .selectByValue ("not there" ));
189
213
}
190
214
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
+
191
224
@ Test
192
225
public void shouldAllowUserToDeselectAllWhenSelectSupportsMultipleSelections () {
193
226
WebElement selectElement = driver .findElement (By .name ("multi" ));
0 commit comments