Skip to content

Commit aeb585b

Browse files
committed
Revert "[java] only allow enabled select lists for Select class"
This reverts commit 25b30ff
1 parent bbc1663 commit aeb585b

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

java/src/org/openqa/selenium/support/ui/Select.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,10 @@ public class Select implements ISelect, WrapsElement {
4545
public Select(WebElement element) {
4646
String tagName = element.getTagName();
4747

48-
if (!"select".equalsIgnoreCase(tagName)) {
48+
if (null == tagName || !"select".equals(tagName.toLowerCase())) {
4949
throw new UnexpectedTagNameException("select", tagName);
5050
}
5151

52-
if (!element.isEnabled()) {
53-
throw new UnsupportedOperationException("Select element is disabled and may not be used.");
54-
}
55-
5652
this.element = element;
5753

5854
String value = element.getDomAttribute("multiple");
@@ -113,6 +109,8 @@ public WebElement getFirstSelectedOption() {
113109
*/
114110
@Override
115111
public void selectByVisibleText(String text) {
112+
assertSelectIsEnabled();
113+
116114
// try to find the option via XPATH ...
117115
List<WebElement> options =
118116
element.findElements(By.xpath(".//option[normalize-space(.) = " + Quotes.escape(text) + "]"));
@@ -177,6 +175,7 @@ private String getLongestSubstringWithoutSpace(String s) {
177175
*/
178176
@Override
179177
public void selectByIndex(int index) {
178+
assertSelectIsEnabled();
180179
setSelectedByIndex(index, true);
181180
}
182181

@@ -191,6 +190,7 @@ public void selectByIndex(int index) {
191190
*/
192191
@Override
193192
public void selectByValue(String value) {
193+
assertSelectIsEnabled();
194194
for (WebElement option : findOptionsByValue(value)) {
195195
setSelected(option, true);
196196
if (!isMultiple()) {
@@ -327,6 +327,12 @@ private void assertOptionIsEnabled(WebElement option, boolean select) {
327327
}
328328
}
329329

330+
private void assertSelectIsEnabled() {
331+
if (!element.isEnabled()) {
332+
throw new UnsupportedOperationException("You may not select an option in disabled select");
333+
}
334+
}
335+
330336
@Override
331337
public boolean equals(Object o) {
332338
if (!(o instanceof Select)) {

java/test/org/openqa/selenium/support/ui/SelectElementTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ void shouldThrowAnExceptionIfTheElementIsNotASelectElement() {
4343
.isThrownBy(() -> new Select(selectElement));
4444
}
4545

46-
@Test
47-
void shouldThrowAnExceptionIfTheElementIsDisabled() {
48-
WebElement selectElement = driver.findElement(By.name("no-select"));
49-
assertThatExceptionOfType(UnsupportedOperationException.class)
50-
.isThrownBy(() -> new Select(selectElement));
51-
}
52-
5346
@Test
5447
void shouldIndicateThatASelectCanSupportMultipleOptions() {
5548
WebElement selectElement = driver.findElement(By.name("multi"));

0 commit comments

Comments
 (0)