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

Method ParseJavaScriptReturnValue

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

Source from the content-addressed store, hash-verified

952 }
953
954 private object? ParseJavaScriptReturnValue(object? responseValue)
955 {
956 object? returnValue;
957
958 if (responseValue is Dictionary<string, object?> resultAsDictionary)
959 {
960 if (this.elementFactory.ContainsElementReference(resultAsDictionary))
961 {
962 returnValue = this.elementFactory.CreateElement(resultAsDictionary);
963 }
964 else if (ShadowRoot.TryCreate(this, resultAsDictionary, out ShadowRoot? shadowRoot))
965 {
966 returnValue = shadowRoot;
967 }
968 else
969 {
970 // Recurse through the dictionary, re-parsing each value.
971 string[] keyCopy = new string[resultAsDictionary.Keys.Count];
972 resultAsDictionary.Keys.CopyTo(keyCopy, 0);
973 foreach (string key in keyCopy)
974 {
975 resultAsDictionary[key] = this.ParseJavaScriptReturnValue(resultAsDictionary[key]);
976 }
977
978 returnValue = resultAsDictionary;
979 }
980 }
981 else if (responseValue is object?[] resultAsArray)
982 {
983 bool allElementsAreWebElements = true;
984 List<object?> toReturn = new List<object?>(resultAsArray.Length);
985 foreach (object? item in resultAsArray)
986 {
987 object? parsedItem = this.ParseJavaScriptReturnValue(item);
988 if (parsedItem is not IWebElement)
989 {
990 allElementsAreWebElements = false;
991 }
992
993 toReturn.Add(parsedItem);
994 }
995
996 if (toReturn.Count > 0 && allElementsAreWebElements)
997 {
998 List<IWebElement> elementList = new List<IWebElement>(resultAsArray.Length);
999 foreach (object? listItem in toReturn)
1000 {
1001 elementList.Add((IWebElement)listItem!);
1002 }
1003
1004 returnValue = elementList.AsReadOnly();
1005 }
1006 else
1007 {
1008 returnValue = toReturn.AsReadOnly();
1009 }
1010 }
1011 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