OpenQA.Selenium.Remote.RemoteWebDriver.ConvertObjectToJavaScriptObject C# (CSharp) Method

ConvertObjectToJavaScriptObject() private static method

private static ConvertObjectToJavaScriptObject ( object arg ) : object
arg object
return object
        private static object ConvertObjectToJavaScriptObject(object arg)
        {
            IWrapsElement argAsWrapsElement = arg as IWrapsElement;
            RemoteWebElement argAsElement = arg as RemoteWebElement;
            IEnumerable argAsEnumerable = arg as IEnumerable;

            if (argAsElement == null && argAsWrapsElement != null)
            {
                argAsElement = argAsWrapsElement.WrappedElement as RemoteWebElement;
            }

            object converted = null;

            if (arg is string || arg is float || arg is double || arg is int || arg is long || arg is bool || arg == null)
            {
                converted = arg;
            }
            else if (argAsElement != null)
            {
                Dictionary<string, object> elementDictionary = new Dictionary<string, object>();
                elementDictionary.Add("ELEMENT", argAsElement.InternalElementId);
                converted = elementDictionary;
            }
            else if (argAsEnumerable != null)
            {
                List<object> objectList = new List<object>();
                foreach (object item in argAsEnumerable)
                {
                    if (item is string || item is float || item is double || item is int || item is long || item is bool || item == null)
                    {
                        objectList.Add(item);
                    }
                    else
                    {
                        throw new ArgumentException("Only primitives may be used as elements in collections used as arguments for JavaScript functions.");
                    }
                }

                converted = objectList.ToArray();
            }
            else
            {
                throw new ArgumentException("Argument is of an illegal type" + arg.ToString(), "arg");
            }

            return converted;
        }

Usage Example

Exemplo n.º 1
0
        private static object ConvertObjectToJavaScriptObject(object arg)
        {
            IWrapsElement    wrapsElement     = arg as IWrapsElement;
            RemoteWebElement remoteWebElement = arg as RemoteWebElement;
            IEnumerable      enumerable       = arg as IEnumerable;
            IDictionary      dictionary       = arg as IDictionary;

            if (remoteWebElement == null && wrapsElement != null)
            {
                remoteWebElement = (wrapsElement.WrappedElement as RemoteWebElement);
            }
            object result;

            if (arg is string || arg is float || arg is double || arg is int || arg is long || arg is bool || arg == null)
            {
                result = arg;
            }
            else if (remoteWebElement != null)
            {
                result = new Dictionary <string, object>
                {
                    {
                        "ELEMENT",
                        remoteWebElement.InternalElementId
                    },
                    {
                        "element-6066-11e4-a52e-4f735466cecf",
                        remoteWebElement.InternalElementId
                    }
                };
            }
            else if (dictionary != null)
            {
                Dictionary <string, object> dictionary2 = new Dictionary <string, object>();
                foreach (object current in dictionary.Keys)
                {
                    dictionary2.Add(current.ToString(), RemoteWebDriver.ConvertObjectToJavaScriptObject(dictionary[current]));
                }
                result = dictionary2;
            }
            else
            {
                if (enumerable == null)
                {
                    throw new ArgumentException("Argument is of an illegal type" + arg.ToString(), "arg");
                }
                List <object> list = new List <object>();
                foreach (object current2 in enumerable)
                {
                    list.Add(RemoteWebDriver.ConvertObjectToJavaScriptObject(current2));
                }
                result = list.ToArray();
            }
            return(result);
        }
All Usage Examples Of OpenQA.Selenium.Remote.RemoteWebDriver::ConvertObjectToJavaScriptObject