@@ -45,14 +45,10 @@ public class Select implements ISelect, WrapsElement {
45
45
public Select (WebElement element ) {
46
46
String tagName = element .getTagName ();
47
47
48
- if (!"select" .equalsIgnoreCase (tagName )) {
48
+ if (null == tagName || !"select" .equals (tagName . toLowerCase () )) {
49
49
throw new UnexpectedTagNameException ("select" , tagName );
50
50
}
51
51
52
- if (!element .isEnabled ()) {
53
- throw new UnsupportedOperationException ("Select element is disabled and may not be used." );
54
- }
55
-
56
52
this .element = element ;
57
53
58
54
String value = element .getDomAttribute ("multiple" );
@@ -113,6 +109,8 @@ public WebElement getFirstSelectedOption() {
113
109
*/
114
110
@ Override
115
111
public void selectByVisibleText (String text ) {
112
+ assertSelectIsEnabled ();
113
+
116
114
// try to find the option via XPATH ...
117
115
List <WebElement > options =
118
116
element .findElements (By .xpath (".//option[normalize-space(.) = " + Quotes .escape (text ) + "]" ));
@@ -177,6 +175,7 @@ private String getLongestSubstringWithoutSpace(String s) {
177
175
*/
178
176
@ Override
179
177
public void selectByIndex (int index ) {
178
+ assertSelectIsEnabled ();
180
179
setSelectedByIndex (index , true );
181
180
}
182
181
@@ -191,6 +190,7 @@ public void selectByIndex(int index) {
191
190
*/
192
191
@ Override
193
192
public void selectByValue (String value ) {
193
+ assertSelectIsEnabled ();
194
194
for (WebElement option : findOptionsByValue (value )) {
195
195
setSelected (option , true );
196
196
if (!isMultiple ()) {
@@ -327,6 +327,12 @@ private void assertOptionIsEnabled(WebElement option, boolean select) {
327
327
}
328
328
}
329
329
330
+ private void assertSelectIsEnabled () {
331
+ if (!element .isEnabled ()) {
332
+ throw new UnsupportedOperationException ("You may not select an option in disabled select" );
333
+ }
334
+ }
335
+
330
336
@ Override
331
337
public boolean equals (Object o ) {
332
338
if (!(o instanceof Select )) {
0 commit comments