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

Method ParseJavaScriptReturnValue

dotnet/src/webdriver/WebDriver.cs:1012–1075  ·  view source on GitHub ↗
(object? responseValue)

Source from the content-addressed store, hash-verified

1010 }
1011
1012 private object? ParseJavaScriptReturnValue(object? responseValue)
1013 {
1014 object? returnValue;
1015
1016 if (responseValue is Dictionary<string, object?> resultAsDictionary)
1017 {
1018 if (this.elementFactory.ContainsElementReference(resultAsDictionary))
1019 {
1020 returnValue = this.elementFactory.CreateElement(resultAsDictionary);
1021 }
1022 else if (ShadowRoot.TryCreate(this, resultAsDictionary, out ShadowRoot? shadowRoot))
1023 {
1024 returnValue = shadowRoot;
1025 }
1026 else
1027 {
1028 // Recurse through the dictionary, re-parsing each value.
1029 string[] keyCopy = new string[resultAsDictionary.Keys.Count];
1030 resultAsDictionary.Keys.CopyTo(keyCopy, 0);
1031 foreach (string key in keyCopy)
1032 {
1033 resultAsDictionary[key] = this.ParseJavaScriptReturnValue(resultAsDictionary[key]);
1034 }
1035
1036 returnValue = resultAsDictionary;
1037 }
1038 }
1039 else if (responseValue is object?[] resultAsArray)
1040 {
1041 bool allElementsAreWebElements = true;
1042 List<object?> toReturn = new List<object?>(resultAsArray.Length);
1043 foreach (object? item in resultAsArray)
1044 {
1045 object? parsedItem = this.ParseJavaScriptReturnValue(item);
1046 if (parsedItem is not IWebElement)
1047 {
1048 allElementsAreWebElements = false;
1049 }
1050
1051 toReturn.Add(parsedItem);
1052 }
1053
1054 if (toReturn.Count > 0 && allElementsAreWebElements)
1055 {
1056 List<IWebElement> elementList = new List<IWebElement>(resultAsArray.Length);
1057 foreach (object? listItem in toReturn)
1058 {
1059 elementList.Add((IWebElement)listItem!);
1060 }
1061
1062 returnValue = elementList.AsReadOnly();
1063 }
1064 else
1065 {
1066 returnValue = toReturn.AsReadOnly();
1067 }
1068 }
1069 else

Callers 1

ExecuteScriptCommandMethod · 0.95

Calls 5

CreateElementMethod · 0.80
TryCreateMethod · 0.80
AddMethod · 0.45
AsReadOnlyMethod · 0.45

Tested by

no test coverage detected