Пример #1
0
        /// <summary>
        /// Move to a frame element.
        /// </summary>
        /// <param name="frameElement">a previously found FRAME or IFRAME element.</param>
        /// <returns>A WebDriver instance that is currently in use.</returns>
        public IWebDriver Frame(IWebElement frameElement)
        {
            if (frameElement == null)
            {
                throw new ArgumentNullException("frameElement", "Frame element cannot be null");
            }

            IWebElementReference elementReference = frameElement as IWebElementReference;

            if (elementReference == null)
            {
                IWrapsElement elementWrapper = frameElement as IWrapsElement;
                if (elementWrapper != null)
                {
                    elementReference = elementWrapper.WrappedElement as IWebElementReference;
                }
            }

            if (elementReference == null)
            {
                throw new ArgumentException("frameElement cannot be converted to IWebElementReference", "frameElement");
            }

            // TODO: Remove "ELEMENT" addition when all remote ends are spec-compliant.
            Dictionary <string, object> elementDictionary = elementReference.ToDictionary();

            elementDictionary.Add("ELEMENT", elementReference.ElementReferenceId);

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("id", elementDictionary);
            this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters);
            return(this.driver);
        }
Пример #2
0
        private static object ConvertObjectToJavaScriptObject(object arg)
        {
            IWrapsElement        argAsWrapsElement     = arg as IWrapsElement;
            IWebElementReference argAsElementReference = arg as IWebElementReference;
            IEnumerable          argAsEnumerable       = arg as IEnumerable;
            IDictionary          argAsDictionary       = arg as IDictionary;

            if (argAsElementReference == null && argAsWrapsElement != null)
            {
                argAsElementReference = argAsWrapsElement.WrappedElement as IWebElementReference;
            }

            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 (argAsElementReference != null)
            {
                // TODO: Remove "ELEMENT" addition when all remote ends are spec-compliant.
                Dictionary <string, object> elementDictionary = argAsElementReference.ToDictionary();
                converted = elementDictionary;
            }
            else if (argAsDictionary != null)
            {
                // Note that we must check for the argument being a dictionary before
                // checking for IEnumerable, since dictionaries also implement IEnumerable.
                // Additionally, JavaScript objects have property names as strings, so all
                // keys will be converted to strings.
                Dictionary <string, object> dictionary = new Dictionary <string, object>();
                foreach (var key in argAsDictionary.Keys)
                {
                    dictionary.Add(key.ToString(), ConvertObjectToJavaScriptObject(argAsDictionary[key]));
                }

                converted = dictionary;
            }
            else if (argAsEnumerable != null)
            {
                List <object> objectList = new List <object>();
                foreach (object item in argAsEnumerable)
                {
                    objectList.Add(ConvertObjectToJavaScriptObject(item));
                }

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

            return(converted);
        }
Пример #3
0
            private Dictionary<string, object> ConvertElement()
            {
                IWebElementReference elementReference = this.target as IWebElementReference;
                if (elementReference == null)
                {
                    IWrapsElement elementWrapper = this.target as IWrapsElement;
                    if (elementWrapper != null)
                    {
                        elementReference = elementWrapper.WrappedElement as IWebElementReference;
                    }
                }

                if (elementReference == null)
                {
                    throw new ArgumentException("Target element cannot be converted to IWebElementReference");
                }

                Dictionary<string, object> elementDictionary = elementReference.ToDictionary();
                return elementDictionary;
            }