Skip to content

Commit 46eea55

Browse files
committed
Align webdriver errors with spec, mitigate breaking change
1 parent 736154e commit 46eea55

File tree

4 files changed

+125
-58
lines changed

4 files changed

+125
-58
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// <copyright file="UnknownMethodException.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using System;
21+
22+
#nullable enable
23+
24+
namespace OpenQA.Selenium
25+
{
26+
/// <summary>
27+
/// Exception that is thrown when the requested command matched a known URL but did not match any method for that URL.
28+
/// </summary>
29+
[Serializable]
30+
public class UnknownMethodException : WebDriverException
31+
{
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="UnknownMethodException"/> class with the specified message.
34+
/// </summary>
35+
/// <param name="message">The message of the exception.</param>
36+
public UnknownMethodException(string? message) : base(message)
37+
{
38+
}
39+
40+
/// <summary>
41+
/// Initializes a new instance of the <see cref="UnknownMethodException"/> class with the specified message and inner exception.
42+
/// </summary>
43+
/// <param name="message">The message of the exception.</param>
44+
/// <param name="innerException">The inner exception for this exception.</param>
45+
public UnknownMethodException(string? message, Exception? innerException) : base(message, innerException)
46+
{
47+
}
48+
}
49+
}

dotnet/src/webdriver/WebDriver.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,9 @@ private static void UnpackAndThrowOnError(Response errorResponse, string command
854854
case WebDriverResult.UnknownError:
855855
throw new UnknownErrorException(errorMessage);
856856

857+
case WebDriverResult.UnknownMethod:
858+
throw new UnknownMethodException(errorMessage);
859+
857860
case WebDriverResult.UnsupportedOperation:
858861
throw new UnsupportedOperationException(errorMessage);
859862

dotnet/src/webdriver/WebDriverError.cs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,16 @@ namespace OpenQA.Selenium
2727
/// </summary>
2828
internal static class WebDriverError
2929
{
30-
/// <summary>
31-
/// Represents the detached shadow root error.
32-
/// </summary>
33-
public const string DetachedShadowRoot = "detached shadow root";
34-
3530
/// <summary>
3631
/// Represents the element click intercepted error.
3732
/// </summary>
3833
public const string ElementClickIntercepted = "element click intercepted";
3934

40-
/// <summary>
41-
/// Represents the element not selectable error.
42-
/// </summary>
43-
public const string ElementNotSelectable = "element not selectable";
44-
4535
/// <summary>
4636
/// Represents the element not interactable error.
4737
/// </summary>
4838
public const string ElementNotInteractable = "element not interactable";
4939

50-
/// <summary>
51-
/// Represents the element not visible error.
52-
/// </summary>
53-
/// TODO: Remove this string; it is no longer valid in the specification.
54-
public const string ElementNotVisible = "element not visible";
55-
5640
/// <summary>
5741
/// Represents the insecure certificate error.
5842
/// </summary>
@@ -68,17 +52,6 @@ internal static class WebDriverError
6852
/// </summary>
6953
public const string InvalidCookieDomain = "invalid cookie domain";
7054

71-
/// <summary>
72-
/// Represents the invalid coordinates error.
73-
/// </summary>
74-
public const string InvalidCoordinates = "invalid coordinates";
75-
76-
/// <summary>
77-
/// Represents the invalid element coordinates error.
78-
/// </summary>
79-
/// TODO: Remove this string; it is no longer valid in the specification.
80-
public const string InvalidElementCoordinates = "invalid element coordinates";
81-
8255
/// <summary>
8356
/// Represents the invalid element state error.
8457
/// </summary>
@@ -149,6 +122,11 @@ internal static class WebDriverError
149122
/// </summary>
150123
public const string StaleElementReference = "stale element reference";
151124

125+
/// <summary>
126+
/// Represents the detached shadow root error.
127+
/// </summary>
128+
public const string DetachedShadowRoot = "detached shadow root";
129+
152130
/// <summary>
153131
/// Represents the timeout error.
154132
/// </summary>
@@ -189,21 +167,38 @@ internal static class WebDriverError
189167
/// </summary>
190168
public const string UnsupportedOperation = "unsupported operation";
191169

170+
/// <summary>
171+
/// Represents the element not selectable error.
172+
/// </summary>
173+
public const string ElementNotSelectable = "element not selectable";
174+
175+
/// <summary>
176+
/// Represents the element not visible error.
177+
/// </summary>
178+
/// TODO: Remove this string; it is no longer valid in the specification.
179+
public const string ElementNotVisible = "element not visible";
180+
181+
/// <summary>
182+
/// Represents the invalid coordinates error.
183+
/// </summary>
184+
public const string InvalidCoordinates = "invalid coordinates";
185+
186+
/// <summary>
187+
/// Represents the invalid element coordinates error.
188+
/// </summary>
189+
/// TODO: Remove this string; it is no longer valid in the specification.
190+
public const string InvalidElementCoordinates = "invalid element coordinates";
191+
192192
private static readonly Dictionary<string, WebDriverResult> resultMap;
193193

194194
static WebDriverError()
195195
{
196196
resultMap = new Dictionary<string, WebDriverResult>();
197-
resultMap[DetachedShadowRoot] = WebDriverResult.DetachedShadowRoot;
198197
resultMap[ElementClickIntercepted] = WebDriverResult.ElementClickIntercepted;
199-
resultMap[ElementNotSelectable] = WebDriverResult.ElementNotSelectable;
200-
resultMap[ElementNotVisible] = WebDriverResult.ElementNotDisplayed;
201198
resultMap[ElementNotInteractable] = WebDriverResult.ElementNotInteractable;
202199
resultMap[InsecureCertificate] = WebDriverResult.InsecureCertificate;
203200
resultMap[InvalidArgument] = WebDriverResult.InvalidArgument;
204201
resultMap[InvalidCookieDomain] = WebDriverResult.InvalidCookieDomain;
205-
resultMap[InvalidCoordinates] = WebDriverResult.InvalidElementCoordinates;
206-
resultMap[InvalidElementCoordinates] = WebDriverResult.InvalidElementCoordinates;
207202
resultMap[InvalidElementState] = WebDriverResult.InvalidElementState;
208203
resultMap[InvalidSelector] = WebDriverResult.InvalidSelector;
209204
resultMap[InvalidSessionId] = WebDriverResult.NoSuchDriver;
@@ -218,14 +213,21 @@ static WebDriverError()
218213
resultMap[ScriptTimeout] = WebDriverResult.AsyncScriptTimeout;
219214
resultMap[SessionNotCreated] = WebDriverResult.SessionNotCreated;
220215
resultMap[StaleElementReference] = WebDriverResult.ObsoleteElement;
216+
resultMap[DetachedShadowRoot] = WebDriverResult.DetachedShadowRoot;
221217
resultMap[Timeout] = WebDriverResult.Timeout;
222218
resultMap[UnableToSetCookie] = WebDriverResult.UnableToSetCookie;
223219
resultMap[UnableToCaptureScreen] = WebDriverResult.UnableToCaptureScreen;
224220
resultMap[UnexpectedAlertOpen] = WebDriverResult.UnexpectedAlertOpen;
225221
resultMap[UnknownCommand] = WebDriverResult.UnknownCommand;
226222
resultMap[UnknownError] = WebDriverResult.UnknownError;
227-
resultMap[UnknownMethod] = WebDriverResult.UnknownCommand;
223+
resultMap[UnknownMethod] = WebDriverResult.UnknownMethod;
228224
resultMap[UnsupportedOperation] = WebDriverResult.UnsupportedOperation;
225+
226+
// TODO: Remove these strings; it is no longer valid in the specification.
227+
resultMap[ElementNotSelectable] = WebDriverResult.ElementNotSelectable;
228+
resultMap[ElementNotVisible] = WebDriverResult.ElementNotDisplayed;
229+
resultMap[InvalidCoordinates] = WebDriverResult.InvalidElementCoordinates;
230+
resultMap[InvalidElementCoordinates] = WebDriverResult.InvalidElementCoordinates;
229231
}
230232

231233
/// <summary>

dotnet/src/webdriver/WebDriverResult.cs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
2022
namespace OpenQA.Selenium
2123
{
2224
/// <summary>
@@ -55,27 +57,27 @@ public enum WebDriverResult
5557
NoStringWrapper = 5,
5658

5759
/// <summary>
58-
/// No driver matching the criteria exists.
60+
/// Occurs if the given <see href="https://www.w3.org/TR/webdriver2/#dfn-session-id">session id</see> is not in the list of <see href="https://www.w3.org/TR/webdriver2/#dfn-active-sessions">active sessions</see>, meaning the session either does not exist or that it's not active.
5961
/// </summary>
6062
NoSuchDriver = 6,
6163

6264
/// <summary>
63-
/// No element matching the criteria exists.
65+
/// An element could not be located on the page using the given search parameters.
6466
/// </summary>
6567
NoSuchElement = 7,
6668

6769
/// <summary>
68-
/// No frame matching the criteria exists.
70+
/// A command to switch to a frame could not be satisfied because the frame could not be found.
6971
/// </summary>
7072
NoSuchFrame = 8,
7173

7274
/// <summary>
73-
/// The functionality is not supported.
75+
/// A command could not be executed because the <see href="https://www.w3.org/TR/webdriver2/#dfn-remote-ends">remote end</see> is not aware of it.
7476
/// </summary>
7577
UnknownCommand = 9,
7678

7779
/// <summary>
78-
/// The specified element is no longer valid.
80+
/// A command failed because the referenced element is no longer attached to the DOM.
7981
/// </summary>
8082
ObsoleteElement = 10,
8183

@@ -85,15 +87,21 @@ public enum WebDriverResult
8587
ElementNotDisplayed = 11,
8688

8789
/// <summary>
88-
/// The specified element is not enabled.
90+
/// A command could not be completed because the element is in an invalid state, e.g. attempting to <see href="https://www.w3.org/TR/webdriver2/#dfn-element-clear">clear</see> an element that isn't both <see href="https://www.w3.org/TR/webdriver2/#dfn-editable">editable</see> and <see href="https://www.w3.org/TR/webdriver2/#dfn-resettable-elements">resettable</see>.
8991
/// </summary>
9092
InvalidElementState = 12,
9193

9294
/// <summary>
93-
/// An unknown error occurred in the remote end while processing the command.
95+
/// An unknown error occurred in the <see href="https://www.w3.org/TR/webdriver2/#dfn-remote-ends">remote end</see> while processing the command.
9496
/// </summary>
9597
UnknownError = 13,
9698

99+
/// <summary>
100+
/// An unhandled error occurred.
101+
/// </summary>
102+
[Obsolete("This value is no longer set for unknown errors: use UnknownError instead")]
103+
UnhandledError = UnknownError,
104+
97105
/// <summary>
98106
/// An error occurred, but it was expected.
99107
/// </summary>
@@ -110,7 +118,7 @@ public enum WebDriverResult
110118
NoSuchDocument = 16,
111119

112120
/// <summary>
113-
/// An unexpected JavaScript error occurred.
121+
/// An error occurred while executing JavaScript supplied by the user.
114122
/// </summary>
115123
UnexpectedJavaScriptError = 17,
116124

@@ -130,7 +138,7 @@ public enum WebDriverResult
130138
NoSuchCollection = 20,
131139

132140
/// <summary>
133-
/// A timeout occurred.
141+
/// An operation did not complete before its timeout expired.
134142
/// </summary>
135143
Timeout = 21,
136144

@@ -140,32 +148,32 @@ public enum WebDriverResult
140148
NullPointer = 22,
141149

142150
/// <summary>
143-
/// No window matching the criteria exists.
151+
/// A command to switch to a window could not be satisfied because the window could not be found.
144152
/// </summary>
145153
NoSuchWindow = 23,
146154

147155
/// <summary>
148-
/// An illegal attempt was made to set a cookie under a different domain than the current page.
156+
/// An illegal attempt was made to set a cookie under a different domain than the current page..
149157
/// </summary>
150158
InvalidCookieDomain = 24,
151159

152160
/// <summary>
153-
/// A request to set a cookie's value could not be satisfied.
161+
/// A command to set a cookie's value could not be satisfied.
154162
/// </summary>
155163
UnableToSetCookie = 25,
156164

157165
/// <summary>
158-
/// An alert was found open unexpectedly.
166+
/// A modal dialog was open, blocking this operation.
159167
/// </summary>
160168
UnexpectedAlertOpen = 26,
161169

162170
/// <summary>
163-
/// A request was made to switch to an alert, but no alert is currently open.
171+
/// An attempt was made to operate on a modal dialog when one was not open.
164172
/// </summary>
165173
NoAlertPresent = 27,
166174

167175
/// <summary>
168-
/// An asynchronous JavaScript execution timed out.
176+
/// A script did not complete before its timeout expired.
169177
/// </summary>
170178
AsyncScriptTimeout = 28,
171179

@@ -175,17 +183,17 @@ public enum WebDriverResult
175183
InvalidElementCoordinates = 29,
176184

177185
/// <summary>
178-
/// The selector used (CSS/XPath) was invalid.
186+
/// Argument was an invalid selector.
179187
/// </summary>
180188
InvalidSelector = 32,
181189

182190
/// <summary>
183-
/// A session was not created by the driver
191+
/// A new <see href="https://www.w3.org/TR/webdriver2/#dfn-sessions">session</see> could not be created.
184192
/// </summary>
185193
SessionNotCreated = 33,
186194

187195
/// <summary>
188-
/// The requested move was outside the active view port
196+
/// The target for mouse interaction is not in the browser's viewport and cannot be brought into that viewport.
189197
/// </summary>
190198
MoveTargetOutOfBounds = 34,
191199

@@ -195,32 +203,32 @@ public enum WebDriverResult
195203
InvalidXPathSelector = 51,
196204

197205
/// <summary>
198-
/// An insecure SSl certificate was specified.
206+
/// Navigation caused the user agent to hit a certificate warning, which is usually the result of an expired or invalid TLS certificate.
199207
/// </summary>
200208
InsecureCertificate = 59,
201209

202210
/// <summary>
203-
/// The element was not interactable
211+
/// A command could not be completed because the element is not <see href="https://www.w3.org/TR/webdriver2/#dfn-pointer-interactable">pointer</see>- or <see href="https://www.w3.org/TR/webdriver2/#dfn-keyboard-interactable">keyboard</see> interactable.
204212
/// </summary>
205213
ElementNotInteractable = 60,
206214

207215
/// <summary>
208-
/// An invalid argument was passed to the command.
216+
/// The arguments passed to a command are either invalid or malformed.
209217
/// </summary>
210218
InvalidArgument = 61,
211219

212220
/// <summary>
213-
/// No cookie was found matching the name requested.
221+
/// No cookie matching the given path name was found amongst the <see href="https://www.w3.org/TR/webdriver2/#dfn-associated-cookies">associated cookies</see> of session's current browsing context's active document.
214222
/// </summary>
215223
NoSuchCookie = 62,
216224

217225
/// <summary>
218-
/// The driver was unable to capture the screen.
226+
/// A screen capture was made impossible.
219227
/// </summary>
220228
UnableToCaptureScreen = 63,
221229

222230
/// <summary>
223-
/// The click on the element was intercepted by a different element.
231+
/// The <see href="https://www.w3.org/TR/webdriver2/#dfn-element-click">Element Click</see> command could not be completed because the element receiving the events is <see href="https://www.w3.org/TR/webdriver2/#dfn-obscuring">obscuring</see> the element that was requested clicked.
224232
/// </summary>
225233
ElementClickIntercepted = 64,
226234

@@ -234,9 +242,14 @@ public enum WebDriverResult
234242
/// </summary>
235243
DetachedShadowRoot = 66,
236244

245+
/// <summary>
246+
/// The requested command matched a known URL but did not match any method for that URL.
247+
/// </summary>
248+
UnknownMethod = 67,
249+
237250
/// <summary>
238251
/// Indicates that a command that should have executed properly cannot be supported for some reason.
239252
/// </summary>
240-
UnsupportedOperation = 67,
253+
UnsupportedOperation = 68,
241254
}
242255
}

0 commit comments

Comments
 (0)