@@ -106,6 +106,8 @@ public string Url
106106 get
107107 {
108108 Response commandResponse = this . Execute ( DriverCommand . GetCurrentUrl , null ) ;
109+
110+ commandResponse . EnsureValueIsNotNull ( ) ;
109111 return commandResponse . Value . ToString ( ) ;
110112 }
111113
@@ -136,6 +138,7 @@ public string PageSource
136138 {
137139 Response commandResponse = this . Execute ( DriverCommand . GetPageSource , null ) ;
138140
141+ commandResponse . EnsureValueIsNotNull ( ) ;
139142 return commandResponse . Value . ToString ( ) ;
140143 }
141144 }
@@ -150,6 +153,7 @@ public string CurrentWindowHandle
150153 {
151154 Response commandResponse = this . Execute ( DriverCommand . GetCurrentWindowHandle , null ) ;
152155
156+ commandResponse . EnsureValueIsNotNull ( ) ;
153157 return commandResponse . Value . ToString ( ) ;
154158 }
155159 }
@@ -162,6 +166,8 @@ public ReadOnlyCollection<string> WindowHandles
162166 get
163167 {
164168 Response commandResponse = this . Execute ( DriverCommand . GetWindowHandles , null ) ;
169+
170+ commandResponse . EnsureValueIsNotNull ( ) ;
165171 object [ ] handles = ( object [ ] ) commandResponse . Value ;
166172 List < string > handleList = new List < string > ( handles . Length ) ;
167173 foreach ( object handle in handles )
@@ -355,7 +361,8 @@ public Screenshot GetScreenshot()
355361 {
356362 Response screenshotResponse = this . Execute ( DriverCommand . Screenshot , null ) ;
357363
358- string base64 = screenshotResponse . Value ? . ToString ( ) ?? throw new WebDriverException ( "Screenshot command returned successfully, but response was empty" ) ;
364+ screenshotResponse . EnsureValueIsNotNull ( ) ;
365+ string base64 = screenshotResponse . Value . ToString ( ) ! ;
359366 return new Screenshot ( base64 ) ;
360367 }
361368
@@ -374,7 +381,8 @@ public PrintDocument Print(PrintOptions printOptions)
374381
375382 Response commandResponse = this . Execute ( DriverCommand . Print , printOptions . ToDictionary ( ) ) ;
376383
377- string base64 = commandResponse . Value ? . ToString ( ) ?? throw new WebDriverException ( "Print command returned successfully, but response was empty" ) ;
384+ commandResponse . EnsureValueIsNotNull ( ) ;
385+ string base64 = commandResponse . Value . ToString ( ) ! ;
378386 return new PrintDocument ( base64 ) ;
379387 }
380388
@@ -653,6 +661,7 @@ protected void StartSession(ICapabilities capabilities)
653661
654662 Response response = this . Execute ( DriverCommand . NewSession , parameters ) ;
655663
664+ response . EnsureValueIsNotNull ( ) ;
656665 if ( response . Value is not Dictionary < string , object > rawCapabilities )
657666 {
658667 string errorMessage = string . Format ( CultureInfo . InvariantCulture , "The new session command returned a value ('{0}') that is not a valid JSON object." , response . Value ) ;
@@ -1044,7 +1053,9 @@ public string AddVirtualAuthenticator(VirtualAuthenticatorOptions options)
10441053 }
10451054
10461055 Response commandResponse = this . Execute ( DriverCommand . AddVirtualAuthenticator , options . ToDictionary ( ) ) ;
1047- string id = ( string ) commandResponse . Value ! ;
1056+
1057+ commandResponse . EnsureValueIsNotNull ( ) ;
1058+ string id = ( string ) commandResponse . Value ;
10481059 this . AuthenticatorId = id ;
10491060 return id ;
10501061 }
@@ -1108,6 +1119,7 @@ public List<Credential> GetCredentials()
11081119
11091120 Response getCredentialsResponse = this . Execute ( driverCommandToExecute : DriverCommand . GetCredentials , parameters ) ;
11101121
1122+ getCredentialsResponse . EnsureValueIsNotNull ( ) ;
11111123 if ( getCredentialsResponse . Value is not object ? [ ] credentialsList )
11121124 {
11131125 throw new WebDriverException ( $ "Get credentials call succeeded, but the response was not a list of credentials: { getCredentialsResponse . Value } ") ;
0 commit comments