@@ -740,124 +740,124 @@ private static void UnpackAndThrowOnError(Response errorResponse, string command
740740 // Check the status code of the error, and only handle if not success.
741741 if ( errorResponse . Status != WebDriverResult . Success )
742742 {
743- if ( errorResponse . Value is not Dictionary < string , object ? > errorAsDictionary )
743+ if ( errorResponse . Value is Dictionary < string , object ? > errorAsDictionary )
744744 {
745- throw new WebDriverException ( $ "The { commandToExecute } command returned an unexpected error. { errorResponse . Value } ") ;
746- }
747-
748- ErrorResponse errorResponseObject = new ErrorResponse ( errorAsDictionary ) ;
749- string errorMessage = errorResponseObject . Message ;
750- switch ( errorResponse . Status )
751- {
752- case WebDriverResult . NoSuchElement :
753- throw new NoSuchElementException ( errorMessage ) ;
745+ ErrorResponse errorResponseObject = new ErrorResponse ( errorAsDictionary ) ;
746+ string errorMessage = errorResponseObject . Message ;
747+ switch ( errorResponse . Status )
748+ {
749+ case WebDriverResult . NoSuchElement :
750+ throw new NoSuchElementException ( errorMessage ) ;
754751
755- case WebDriverResult . NoSuchFrame :
756- throw new NoSuchFrameException ( errorMessage ) ;
752+ case WebDriverResult . NoSuchFrame :
753+ throw new NoSuchFrameException ( errorMessage ) ;
757754
758- case WebDriverResult . UnknownCommand :
759- throw new NotImplementedException ( errorMessage ) ;
755+ case WebDriverResult . UnknownCommand :
756+ throw new NotImplementedException ( errorMessage ) ;
760757
761- case WebDriverResult . ObsoleteElement :
762- throw new StaleElementReferenceException ( errorMessage ) ;
758+ case WebDriverResult . ObsoleteElement :
759+ throw new StaleElementReferenceException ( errorMessage ) ;
763760
764- case WebDriverResult . ElementClickIntercepted :
765- throw new ElementClickInterceptedException ( errorMessage ) ;
761+ case WebDriverResult . ElementClickIntercepted :
762+ throw new ElementClickInterceptedException ( errorMessage ) ;
766763
767- case WebDriverResult . ElementNotInteractable :
768- throw new ElementNotInteractableException ( errorMessage ) ;
764+ case WebDriverResult . ElementNotInteractable :
765+ throw new ElementNotInteractableException ( errorMessage ) ;
769766
770- case WebDriverResult . ElementNotDisplayed :
771- throw new ElementNotVisibleException ( errorMessage ) ;
767+ case WebDriverResult . ElementNotDisplayed :
768+ throw new ElementNotVisibleException ( errorMessage ) ;
772769
773- case WebDriverResult . InvalidElementState :
774- case WebDriverResult . ElementNotSelectable :
775- throw new InvalidElementStateException ( errorMessage ) ;
770+ case WebDriverResult . InvalidElementState :
771+ case WebDriverResult . ElementNotSelectable :
772+ throw new InvalidElementStateException ( errorMessage ) ;
776773
777- case WebDriverResult . NoSuchDocument :
778- throw new NoSuchElementException ( errorMessage ) ;
774+ case WebDriverResult . NoSuchDocument :
775+ throw new NoSuchElementException ( errorMessage ) ;
779776
780- case WebDriverResult . Timeout :
781- throw new WebDriverTimeoutException ( errorMessage ) ;
777+ case WebDriverResult . Timeout :
778+ throw new WebDriverTimeoutException ( errorMessage ) ;
782779
783- case WebDriverResult . NoSuchWindow :
784- throw new NoSuchWindowException ( errorMessage ) ;
780+ case WebDriverResult . NoSuchWindow :
781+ throw new NoSuchWindowException ( errorMessage ) ;
785782
786- case WebDriverResult . InvalidCookieDomain :
787- throw new InvalidCookieDomainException ( errorMessage ) ;
783+ case WebDriverResult . InvalidCookieDomain :
784+ throw new InvalidCookieDomainException ( errorMessage ) ;
788785
789- case WebDriverResult . UnableToSetCookie :
790- throw new UnableToSetCookieException ( errorMessage ) ;
786+ case WebDriverResult . UnableToSetCookie :
787+ throw new UnableToSetCookieException ( errorMessage ) ;
791788
792- case WebDriverResult . AsyncScriptTimeout :
793- throw new WebDriverTimeoutException ( errorMessage ) ;
789+ case WebDriverResult . AsyncScriptTimeout :
790+ throw new WebDriverTimeoutException ( errorMessage ) ;
794791
795- case WebDriverResult . UnexpectedAlertOpen :
796- // TODO(JimEvans): Handle the case where the unexpected alert setting
797- // has been set to "ignore", so there is still a valid alert to be
798- // handled.
799- string ? alertText = null ;
800- if ( errorAsDictionary . TryGetValue ( "alert" , out object ? alert ) )
801- {
802- if ( alert is Dictionary < string , object ? > alertDescription
803- && alertDescription . TryGetValue ( "text" , out object ? text ) )
792+ case WebDriverResult . UnexpectedAlertOpen :
793+ // TODO(JimEvans): Handle the case where the unexpected alert setting
794+ // has been set to "ignore", so there is still a valid alert to be
795+ // handled.
796+ string ? alertText = null ;
797+ if ( errorAsDictionary . TryGetValue ( "alert" , out object ? alert ) )
804798 {
805- alertText = text ? . ToString ( ) ;
799+ if ( alert is Dictionary < string , object ? > alertDescription
800+ && alertDescription . TryGetValue ( "text" , out object ? text ) )
801+ {
802+ alertText = text ? . ToString ( ) ;
803+ }
806804 }
807- }
808- else if ( errorAsDictionary . TryGetValue ( "data" , out object ? data ) )
809- {
810- if ( data is Dictionary < string , object ? > alertData
811- && alertData . TryGetValue ( "text" , out object ? dataText ) )
805+ else if ( errorAsDictionary . TryGetValue ( "data" , out object ? data ) )
812806 {
813- alertText = dataText ? . ToString ( ) ;
807+ if ( data is Dictionary < string , object ? > alertData
808+ && alertData . TryGetValue ( "text" , out object ? dataText ) )
809+ {
810+ alertText = dataText ? . ToString ( ) ;
811+ }
814812 }
815- }
816813
817- throw new UnhandledAlertException ( errorMessage , alertText ?? string . Empty ) ;
814+ throw new UnhandledAlertException ( errorMessage , alertText ?? string . Empty ) ;
818815
819- case WebDriverResult . NoAlertPresent :
820- throw new NoAlertPresentException ( errorMessage ) ;
816+ case WebDriverResult . NoAlertPresent :
817+ throw new NoAlertPresentException ( errorMessage ) ;
821818
822- case WebDriverResult . InvalidSelector :
823- throw new InvalidSelectorException ( errorMessage ) ;
819+ case WebDriverResult . InvalidSelector :
820+ throw new InvalidSelectorException ( errorMessage ) ;
824821
825- case WebDriverResult . NoSuchDriver :
826- throw new WebDriverException ( errorMessage ) ;
822+ case WebDriverResult . NoSuchDriver :
823+ throw new WebDriverException ( errorMessage ) ;
827824
828- case WebDriverResult . InvalidArgument :
829- throw new WebDriverArgumentException ( errorMessage ) ;
825+ case WebDriverResult . InvalidArgument :
826+ throw new WebDriverArgumentException ( errorMessage ) ;
830827
831- case WebDriverResult . UnexpectedJavaScriptError :
832- throw new JavaScriptException ( errorMessage ) ;
828+ case WebDriverResult . UnexpectedJavaScriptError :
829+ throw new JavaScriptException ( errorMessage ) ;
833830
834- case WebDriverResult . MoveTargetOutOfBounds :
835- throw new MoveTargetOutOfBoundsException ( errorMessage ) ;
831+ case WebDriverResult . MoveTargetOutOfBounds :
832+ throw new MoveTargetOutOfBoundsException ( errorMessage ) ;
836833
837- case WebDriverResult . NoSuchShadowRoot :
838- throw new NoSuchShadowRootException ( errorMessage ) ;
834+ case WebDriverResult . NoSuchShadowRoot :
835+ throw new NoSuchShadowRootException ( errorMessage ) ;
839836
840- case WebDriverResult . DetachedShadowRoot :
841- throw new DetachedShadowRootException ( errorMessage ) ;
837+ case WebDriverResult . DetachedShadowRoot :
838+ throw new DetachedShadowRootException ( errorMessage ) ;
842839
843- case WebDriverResult . InsecureCertificate :
844- throw new InsecureCertificateException ( errorMessage ) ;
840+ case WebDriverResult . InsecureCertificate :
841+ throw new InsecureCertificateException ( errorMessage ) ;
845842
846- case WebDriverResult . UnknownError :
847- throw new UnknownErrorException ( errorMessage ) ;
843+ case WebDriverResult . UnknownError :
844+ throw new UnknownErrorException ( errorMessage ) ;
848845
849- case WebDriverResult . UnknownMethod :
850- throw new UnknownMethodException ( errorMessage ) ;
846+ case WebDriverResult . UnknownMethod :
847+ throw new UnknownMethodException ( errorMessage ) ;
851848
852- case WebDriverResult . UnsupportedOperation :
853- throw new UnsupportedOperationException ( errorMessage ) ;
849+ case WebDriverResult . UnsupportedOperation :
850+ throw new UnsupportedOperationException ( errorMessage ) ;
854851
855- case WebDriverResult . NoSuchCookie :
856- throw new NoSuchCookieException ( errorMessage ) ;
852+ case WebDriverResult . NoSuchCookie :
853+ throw new NoSuchCookieException ( errorMessage ) ;
857854
858- default :
859- throw new InvalidOperationException ( string . Format ( CultureInfo . InvariantCulture , "{0} ({1})" , errorMessage , errorResponse . Status ) ) ;
855+ default :
856+ throw new InvalidOperationException ( string . Format ( CultureInfo . InvariantCulture , "{0} ({1})" , errorMessage , errorResponse . Status ) ) ;
857+ }
860858 }
859+
860+ throw new WebDriverException ( $ "The { commandToExecute } command returned an unexpected error. { errorResponse . Value } ") ;
861861 }
862862 }
863863
0 commit comments