26
26
import org .junit .Before ;
27
27
import org .junit .Test ;
28
28
import org .openqa .selenium .By ;
29
+ import org .openqa .selenium .NoSuchElementException ;
29
30
import org .openqa .selenium .WebElement ;
30
31
import org .openqa .selenium .testing .Ignore ;
31
32
import org .openqa .selenium .testing .JUnit4TestBase ;
@@ -39,7 +40,7 @@ public void runBeforeEveryTest() {
39
40
driver .get (pages .formPage );
40
41
}
41
42
42
- @ Test (expected = org . openqa . selenium . support . ui . UnexpectedTagNameException .class )
43
+ @ Test (expected = UnexpectedTagNameException .class )
43
44
public void shouldThrowAnExceptionIfTheElementIsNotASelectElement () {
44
45
WebElement selectElement = driver .findElement (By .name ("checky" ));
45
46
Select select = new Select (selectElement );
@@ -141,7 +142,7 @@ public void shouldReturnFirstSelectedOption() {
141
142
assertEquals ("Eggs" ,firstSelected .getText ());
142
143
}
143
144
144
- @ Test (expected = org . openqa . selenium . NoSuchElementException .class )
145
+ @ Test (expected = NoSuchElementException .class )
145
146
public void shouldThrowANoSuchElementExceptionIfNothingIsSelected () {
146
147
WebElement selectElement = driver .findElement (By .name ("select_empty_multiple" ));
147
148
Select select = new Select (selectElement );
@@ -158,14 +159,14 @@ public void shouldAllowOptionsToBeSelectedByVisibleText() {
158
159
assertEquals ("select_2" ,firstSelected .getText ());
159
160
}
160
161
161
- @ Test (expected = org . openqa . selenium . NoSuchElementException .class )
162
+ @ Test (expected = NoSuchElementException .class )
162
163
public void shouldNotAllowInvisibleOptionsToBeSelectedByVisibleText () {
163
164
WebElement selectElement = driver .findElement (By .name ("invisi_select" ));
164
165
Select select = new Select (selectElement );
165
166
select .selectByVisibleText ("Apples" );
166
167
}
167
168
168
- @ Test (expected = org . openqa . selenium . NoSuchElementException .class )
169
+ @ Test (expected = NoSuchElementException .class )
169
170
public void shouldThrowExceptionOnSelectByVisibleTextIfOptionDoesNotExist () {
170
171
WebElement selectElement = driver .findElement (By .name ("select_empty_multiple" ));
171
172
Select select = new Select (selectElement );
@@ -181,7 +182,7 @@ public void shouldAllowOptionsToBeSelectedByIndex() {
181
182
assertEquals ("select_2" ,firstSelected .getText ());
182
183
}
183
184
184
- @ Test (expected = org . openqa . selenium . NoSuchElementException .class )
185
+ @ Test (expected = NoSuchElementException .class )
185
186
public void shouldThrowExceptionOnSelectByIndexIfOptionDoesNotExist () {
186
187
WebElement selectElement = driver .findElement (By .name ("select_empty_multiple" ));
187
188
Select select = new Select (selectElement );
@@ -197,7 +198,7 @@ public void shouldAllowOptionsToBeSelectedByReturnedValue() {
197
198
assertEquals ("select_2" ,firstSelected .getText ());
198
199
}
199
200
200
- @ Test (expected = org . openqa . selenium . NoSuchElementException .class )
201
+ @ Test (expected = NoSuchElementException .class )
201
202
public void shouldThrowExceptionOnSelectByReturnedValueIfOptionDoesNotExist () {
202
203
WebElement selectElement = driver .findElement (By .name ("select_empty_multiple" ));
203
204
Select select = new Select (selectElement );
@@ -215,7 +216,7 @@ public void shouldAllowUserToDeselectAllWhenSelectSupportsMultipleSelections() {
215
216
assertEquals (0 ,returnedOptions .size ());
216
217
}
217
218
218
- @ Test (expected = java . lang . UnsupportedOperationException .class )
219
+ @ Test (expected = UnsupportedOperationException .class )
219
220
public void shouldNotAllowUserToDeselectAllWhenSelectDoesNotSupportMultipleSelections () {
220
221
WebElement selectElement = driver .findElement (By .name ("selectomatic" ));
221
222
Select select = new Select (selectElement );
@@ -232,7 +233,7 @@ public void shouldAllowUserToDeselectOptionsByVisibleText() {
232
233
assertEquals (1 ,returnedOptions .size ());
233
234
}
234
235
235
- @ Test (expected = org . openqa . selenium . NoSuchElementException .class )
236
+ @ Test (expected = NoSuchElementException .class )
236
237
public void shouldNotAllowUserToDeselectOptionsByInvisibleText () {
237
238
WebElement selectElement = driver .findElement (By .name ("invisi_select" ));
238
239
Select select = new Select (selectElement );
@@ -258,4 +259,15 @@ public void shouldAllowOptionsToBeDeselectedByReturnedValue() {
258
259
259
260
assertEquals (1 ,returnedOptions .size ());
260
261
}
262
+
263
+ @ Test
264
+ public void shouldAllowOptionsToBeSelectedFromTheSelectElementThatIsNarrowerThanOptions () {
265
+ driver .get (pages .selectPage );
266
+ WebElement selectElement = driver .findElement (By .id ("narrow" ));
267
+ Select select = new Select (selectElement );
268
+ select .selectByIndex (1 );
269
+ List <WebElement > returnedOptions = select .getAllSelectedOptions ();
270
+
271
+ assertEquals (1 ,returnedOptions .size ());
272
+ }
261
273
}
0 commit comments