28
28
using System . Globalization ;
29
29
using System . Threading . Tasks ;
30
30
31
+ #nullable enable
32
+
31
33
namespace OpenQA . Selenium
32
34
{
33
35
/// <summary>
@@ -40,10 +42,10 @@ public class WebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFinds
40
42
/// </summary>
41
43
protected static readonly TimeSpan DefaultCommandTimeout = TimeSpan . FromSeconds ( 60 ) ;
42
44
private IFileDetector fileDetector = new DefaultFileDetector ( ) ;
43
- private NetworkManager network ;
45
+ private readonly NetworkManager network ;
44
46
private WebElementFactory elementFactory ;
45
47
46
- private List < string > registeredCommands = new List < string > ( ) ;
48
+ private readonly List < string > registeredCommands = new List < string > ( ) ;
47
49
48
50
/// <summary>
49
51
/// Initializes a new instance of the <see cref="WebDriver"/> class.
@@ -108,7 +110,7 @@ public string Url
108
110
Response commandResponse = this . Execute ( DriverCommand . GetCurrentUrl , null ) ;
109
111
110
112
commandResponse . EnsureValueIsNotNull ( ) ;
111
- return commandResponse . Value . ToString ( ) ;
113
+ return commandResponse . Value . ToString ( ) ! ;
112
114
}
113
115
114
116
set => new Navigator ( this ) . GoToUrl ( value ) ;
@@ -122,13 +124,11 @@ public string Title
122
124
get
123
125
{
124
126
Response commandResponse = this . Execute ( DriverCommand . GetTitle , null ) ;
125
- object returnedTitle = commandResponse . Value ?? string . Empty ;
126
127
127
- return returnedTitle . ToString ( ) ;
128
+ return commandResponse . Value ? . ToString ( ) ?? string . Empty ;
128
129
}
129
130
}
130
131
131
-
132
132
/// <summary>
133
133
/// Gets the source of the page last loaded by the browser.
134
134
/// </summary>
@@ -139,7 +139,7 @@ public string PageSource
139
139
Response commandResponse = this . Execute ( DriverCommand . GetPageSource , null ) ;
140
140
141
141
commandResponse . EnsureValueIsNotNull ( ) ;
142
- return commandResponse . Value . ToString ( ) ;
142
+ return commandResponse . Value . ToString ( ) ! ;
143
143
}
144
144
}
145
145
@@ -154,7 +154,7 @@ public string CurrentWindowHandle
154
154
Response commandResponse = this . Execute ( DriverCommand . GetCurrentWindowHandle , null ) ;
155
155
156
156
commandResponse . EnsureValueIsNotNull ( ) ;
157
- return commandResponse . Value . ToString ( ) ;
157
+ return commandResponse . Value . ToString ( ) ! ;
158
158
}
159
159
}
160
160
@@ -168,11 +168,11 @@ public ReadOnlyCollection<string> WindowHandles
168
168
Response commandResponse = this . Execute ( DriverCommand . GetWindowHandles , null ) ;
169
169
170
170
commandResponse . EnsureValueIsNotNull ( ) ;
171
- object [ ] handles = ( object [ ] ) commandResponse . Value ;
171
+ object ? [ ] handles = ( object ? [ ] ) commandResponse . Value ;
172
172
List < string > handleList = new List < string > ( handles . Length ) ;
173
- foreach ( object handle in handles )
173
+ foreach ( object ? handle in handles )
174
174
{
175
- handleList . Add ( handle . ToString ( ) ) ;
175
+ handleList . Add ( handle ! . ToString ( ) ! ) ;
176
176
}
177
177
178
178
return handleList . AsReadOnly ( ) ;
@@ -184,8 +184,6 @@ public ReadOnlyCollection<string> WindowHandles
184
184
/// </summary>
185
185
public bool IsActionExecutor => true ;
186
186
187
- #nullable enable
188
-
189
187
/// <summary>
190
188
/// Gets the <see cref="Selenium.SessionId"/> for the current session of this driver.
191
189
/// </summary>
@@ -272,8 +270,6 @@ public void Dispose()
272
270
return this . ExecuteScript ( script . MakeExecutionScript ( ) , args ) ;
273
271
}
274
272
275
- #nullable restore
276
-
277
273
/// <summary>
278
274
/// Finds the first element in the page that matches the <see cref="By"/> object
279
275
/// </summary>
@@ -310,7 +306,7 @@ public virtual IWebElement FindElement(string mechanism, string value)
310
306
311
307
Response commandResponse = this . Execute ( DriverCommand . FindElement , parameters ) ;
312
308
313
- return this . GetElementFromResponse ( commandResponse ) ;
309
+ return this . GetElementFromResponse ( commandResponse ) ! ;
314
310
}
315
311
316
312
/// <summary>
@@ -351,8 +347,6 @@ public virtual ReadOnlyCollection<IWebElement> FindElements(string mechanism, st
351
347
return this . GetElementsFromResponse ( commandResponse ) ;
352
348
}
353
349
354
- #nullable enable
355
-
356
350
/// <summary>
357
351
/// Gets a <see cref="Screenshot"/> object representing the image of the page on the screen.
358
352
/// </summary>
@@ -527,14 +521,8 @@ internal bool RegisterDriverCommand(string commandName, [NotNullWhen(true)] Comm
527
521
/// </summary>
528
522
/// <param name="response">Response from the browser</param>
529
523
/// <returns>Element from the page, or <see langword="null"/> if the response does not contain a dictionary.</returns>
530
- /// <exception cref="ArgumentNullException">If <paramref name="response"/> is <see langword="null"/>.</exception>
531
524
internal IWebElement ? GetElementFromResponse ( Response response )
532
525
{
533
- if ( response == null )
534
- {
535
- throw new NoSuchElementException ( ) ;
536
- }
537
-
538
526
if ( response . Value is Dictionary < string , object ? > elementDictionary )
539
527
{
540
528
return this . elementFactory . CreateElement ( elementDictionary ) ;
@@ -566,16 +554,18 @@ internal ReadOnlyCollection<IWebElement> GetElementsFromResponse(Response respon
566
554
return toReturn . AsReadOnly ( ) ;
567
555
}
568
556
569
- #nullable restore
570
-
571
557
/// <summary>
572
558
/// Executes commands with the driver
573
559
/// </summary>
574
560
/// <param name="driverCommandToExecute">Command that needs executing</param>
575
561
/// <param name="parameters">Parameters needed for the command</param>
576
562
/// <returns>WebDriver Response</returns>
577
563
/// <exception cref="ArgumentNullException">If <paramref name="driverCommandToExecute"/> is <see langword="null"/>.</exception>
578
- internal Response InternalExecute ( string driverCommandToExecute , Dictionary < string , object > parameters )
564
+ internal Response InternalExecute ( string driverCommandToExecute , Dictionary < string ,
565
+ #nullable disable
566
+ object
567
+ #nullable enable
568
+ > ? parameters )
579
569
{
580
570
return Task . Run ( ( ) => this . InternalExecuteAsync ( driverCommandToExecute , parameters ) ) . GetAwaiter ( ) . GetResult ( ) ;
581
571
}
@@ -587,8 +577,11 @@ internal Response InternalExecute(string driverCommandToExecute, Dictionary<stri
587
577
/// <param name="parameters">Parameters needed for the command</param>
588
578
/// <returns>A task object representing the asynchronous operation</returns>
589
579
/// <exception cref="ArgumentNullException">If <paramref name="driverCommandToExecute"/> is <see langword="null"/>.</exception>
590
- internal Task < Response > InternalExecuteAsync ( string driverCommandToExecute ,
591
- Dictionary < string , object > parameters )
580
+ internal Task < Response > InternalExecuteAsync ( string driverCommandToExecute , Dictionary < string ,
581
+ #nullable disable
582
+ object
583
+ #nullable enable
584
+ > ? parameters )
592
585
{
593
586
return this . ExecuteAsync ( driverCommandToExecute , parameters ) ;
594
587
}
@@ -600,8 +593,11 @@ internal Task<Response> InternalExecuteAsync(string driverCommandToExecute,
600
593
/// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing the names and values of the parameters of the command.</param>
601
594
/// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
602
595
/// <exception cref="ArgumentNullException">If <paramref name="driverCommandToExecute"/> is <see langword="null"/>.</exception>
603
- protected virtual Response Execute ( string driverCommandToExecute ,
604
- Dictionary < string , object > parameters )
596
+ protected virtual Response Execute ( string driverCommandToExecute , Dictionary < string ,
597
+ #nullable disable
598
+ object
599
+ #nullable enable
600
+ > ? parameters )
605
601
{
606
602
return Task . Run ( ( ) => this . ExecuteAsync ( driverCommandToExecute , parameters ) ) . GetAwaiter ( ) . GetResult ( ) ;
607
603
}
@@ -613,7 +609,11 @@ protected virtual Response Execute(string driverCommandToExecute,
613
609
/// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing the names and values of the parameters of the command.</param>
614
610
/// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
615
611
/// <exception cref="ArgumentNullException">If <paramref name="driverCommandToExecute"/> is <see langword="null"/>.</exception>
616
- protected virtual async Task < Response > ExecuteAsync ( string driverCommandToExecute , Dictionary < string , object > parameters )
612
+ protected virtual async Task < Response > ExecuteAsync ( string driverCommandToExecute , Dictionary < string ,
613
+ #nullable disable
614
+ object
615
+ #nullable enable
616
+ > ? parameters )
617
617
{
618
618
Command commandToExecute = new Command ( SessionId , driverCommandToExecute , parameters ) ;
619
619
@@ -702,8 +702,6 @@ protected virtual Dictionary<string, object> GetCapabilitiesDictionary(ICapabili
702
702
return capabilitiesDictionary ;
703
703
}
704
704
705
- #nullable enable
706
-
707
705
/// <summary>
708
706
/// Registers a command to be executed with this driver instance as an internally known driver command.
709
707
/// </summary>
0 commit comments