MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / UnpackAndThrowOnError

Method UnpackAndThrowOnError

dotnet/src/webdriver/WebDriver.cs:794–911  ·  view source on GitHub ↗
(Response errorResponse, string commandToExecute)

Source from the content-addressed store, hash-verified

792 }
793
794 private static void UnpackAndThrowOnError(Response errorResponse, string commandToExecute)
795 {
796 // Check the status code of the error, and only handle if not success.
797 if (errorResponse.Status != WebDriverResult.Success)
798 {
799 if (errorResponse.Value is Dictionary<string, object?> errorAsDictionary)
800 {
801 ErrorResponse errorResponseObject = new ErrorResponse(errorAsDictionary);
802 string errorMessage = errorResponseObject.Message;
803 switch (errorResponse.Status)
804 {
805 case WebDriverResult.NoSuchElement:
806 throw new NoSuchElementException(errorMessage);
807
808 case WebDriverResult.NoSuchFrame:
809 throw new NoSuchFrameException(errorMessage);
810
811 case WebDriverResult.UnknownCommand:
812 throw new NotImplementedException(errorMessage);
813
814 case WebDriverResult.ObsoleteElement:
815 throw new StaleElementReferenceException(errorMessage);
816
817 case WebDriverResult.ElementClickIntercepted:
818 throw new ElementClickInterceptedException(errorMessage);
819
820 case WebDriverResult.ElementNotInteractable:
821 throw new ElementNotInteractableException(errorMessage);
822
823 case WebDriverResult.InvalidElementState:
824 throw new InvalidElementStateException(errorMessage);
825
826 case WebDriverResult.Timeout:
827 throw new WebDriverTimeoutException(errorMessage);
828
829 case WebDriverResult.NoSuchWindow:
830 throw new NoSuchWindowException(errorMessage);
831
832 case WebDriverResult.InvalidCookieDomain:
833 throw new InvalidCookieDomainException(errorMessage);
834
835 case WebDriverResult.UnableToSetCookie:
836 throw new UnableToSetCookieException(errorMessage);
837
838 case WebDriverResult.AsyncScriptTimeout:
839 throw new WebDriverTimeoutException(errorMessage);
840
841 case WebDriverResult.UnexpectedAlertOpen:
842 // TODO(JimEvans): Handle the case where the unexpected alert setting
843 // has been set to "ignore", so there is still a valid alert to be
844 // handled.
845 string? alertText = null;
846 if (errorAsDictionary.TryGetValue("alert", out object? alert))
847 {
848 if (alert is Dictionary<string, object?> alertDescription
849 && alertDescription.TryGetValue("text", out object? text))
850 {
851 alertText = text?.ToString();

Callers

nothing calls this directly

Calls 2

FormatMethod · 0.80
TryGetValueMethod · 0.45

Tested by

no test coverage detected