+48
-1
lines changedFilter options
+48
-1
lines changed Original file line number Diff line number Diff line change
@@ -44,6 +44,11 @@ public SelectElement(IWebElement element)
44
44
throw new ArgumentNullException(nameof(element), "element cannot be null");
45
45
}
46
46
47
+
if (!element.Enabled)
48
+
{
49
+
throw new InvalidOperationException("Select element is disabled and may not be used.");
50
+
}
51
+
47
52
string tagName = element.TagName;
48
53
49
54
if (string.IsNullOrEmpty(tagName) || string.Compare(tagName, "select", StringComparison.OrdinalIgnoreCase) != 0)
@@ -446,6 +451,10 @@ private static string GetLongestSubstringWithoutSpace(string s)
446
451
447
452
private static void SetSelected(IWebElement option, bool select)
448
453
{
454
+
if (select && !option.Enabled) {
455
+
throw new InvalidOperationException("You may not select a disabled option");
456
+
}
457
+
449
458
bool isSelected = option.Selected;
450
459
if ((!isSelected && select) || (isSelected && !select))
451
460
{
Original file line number Diff line number Diff line change
@@ -34,6 +34,13 @@ public void ShouldThrowAnExceptionIfTheElementIsNotASelectElement()
34
34
Assert.Throws<UnexpectedTagNameException>(() => { SelectElement elementWrapper = new SelectElement(element); });
35
35
}
36
36
37
+
[Test]
38
+
public void ShouldThrowAnExceptionIfTheElementIsNotEnabled()
39
+
{
40
+
IWebElement element = driver.FindElement(By.Name("no-select"));
41
+
Assert.Throws<InvalidOperationException>(() => { SelectElement elementWrapper = new SelectElement(element); });
42
+
}
43
+
37
44
[Test]
38
45
public void ShouldIndicateThatASelectCanSupportMultipleOptions()
39
46
{
@@ -141,7 +148,7 @@ public void ShouldReturnFirstSelectedOption()
141
148
142
149
// [Test]
143
150
// [ExpectedException(typeof(NoSuchElementException))]
144
-
// The .NET bindings do not have a "FirstSelectedOption" property,
151
+
// The .NET bindings do not have a "FirstSelectedOption" property,
145
152
// and no one has asked for it to this point. Given that, this test
146
153
// is not a valid test.
147
154
public void ShouldThrowANoSuchElementExceptionIfNothingIsSelected()
@@ -196,6 +203,14 @@ public void ShouldThrowExceptionOnSelectByVisibleTextIfOptionDoesNotExist()
196
203
Assert.Throws<NoSuchElementException>(() => elementWrapper.SelectByText("not there"));
197
204
}
198
205
206
+
[Test]
207
+
public void ShouldThrowExceptionOnSelectByVisibleTextIfOptionDisabled()
208
+
{
209
+
IWebElement element = driver.FindElement(By.Name("single_disabled"));
210
+
SelectElement elementWrapper = new SelectElement(element);
211
+
Assert.Throws<NoSuchElementException>(() => elementWrapper.SelectByText("Disabled"));
212
+
}
213
+
199
214
[Test]
200
215
public void ShouldAllowOptionsToBeSelectedByIndex()
201
216
{
@@ -214,6 +229,14 @@ public void ShouldThrowExceptionOnSelectByIndexIfOptionDoesNotExist()
214
229
Assert.Throws<NoSuchElementException>(() => elementWrapper.SelectByIndex(10));
215
230
}
216
231
232
+
[Test]
233
+
public void ShouldThrowExceptionOnSelectByIndexIfOptionDisabled()
234
+
{
235
+
IWebElement element = driver.FindElement(By.Name("single_disabled"));
236
+
SelectElement elementWrapper = new SelectElement(element);
237
+
Assert.Throws<NoSuchElementException>(() => elementWrapper.SelectByIndex(1));
238
+
}
239
+
217
240
[Test]
218
241
public void ShouldAllowOptionsToBeSelectedByReturnedValue()
219
242
{
@@ -232,6 +255,14 @@ public void ShouldThrowExceptionOnSelectByReturnedValueIfOptionDoesNotExist()
232
255
Assert.Throws<NoSuchElementException>(() => elementWrapper.SelectByValue("not there"));
233
256
}
234
257
258
+
[Test]
259
+
public void ShouldThrowExceptionOnSelectByReturnedValueIfOptionDisabled()
260
+
{
261
+
IWebElement element = driver.FindElement(By.Name("single_disabled"));
262
+
SelectElement elementWrapper = new SelectElement(element);
263
+
Assert.Throws<NoSuchElementException>(() => elementWrapper.SelectByValue("disabled"));
264
+
}
265
+
235
266
[Test]
236
267
public void ShouldAllowUserToDeselectAllWhenSelectSupportsMultipleSelections()
237
268
{
Original file line number Diff line number Diff line change
@@ -25,6 +25,13 @@ public void ThrowUnexpectedTagNameExceptionWhenNotSelectTag()
25
25
Assert.Throws<UnexpectedTagNameException>(() => new SelectElement(webElement.Object));
26
26
}
27
27
28
+
[Test]
29
+
public void ThrowUnexpectedTagNameExceptionWhenNotEnabled()
30
+
{
31
+
webElement.SetupGet<bool>(_ => _.Enabled).Returns(false);
32
+
Assert.Throws<InvalidOperationException>(() => new SelectElement(webElement.Object));
33
+
}
34
+
28
35
[Test]
29
36
public void CanCreateNewInstanceOfSelectWithNormalSelectElement()
30
37
{
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4