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