/// <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(nameof(frameElement), "Frame element cannot be null"); } IWebDriverObjectReference elementReference = frameElement as IWebDriverObjectReference; if (elementReference == null) { IWrapsElement elementWrapper = frameElement as IWrapsElement; if (elementWrapper != null) { elementReference = elementWrapper.WrappedElement as IWebDriverObjectReference; } } if (elementReference == null) { throw new ArgumentException("frameElement cannot be converted to IWebElementReference", nameof(frameElement)); } // TODO: Remove "ELEMENT" addition when all remote ends are spec-compliant. Dictionary <string, object> elementDictionary = elementReference.ToDictionary(); elementDictionary.Add("ELEMENT", elementReference.ObjectReferenceId); Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("id", elementDictionary); this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters); return(this.driver); }
private static object ConvertObjectToJavaScriptObject(object arg) { IWrapsElement argAsWrapsElement = arg as IWrapsElement; IWebDriverObjectReference argAsObjectReference = arg as IWebDriverObjectReference; IEnumerable argAsEnumerable = arg as IEnumerable; IDictionary argAsDictionary = arg as IDictionary; if (argAsObjectReference == null && argAsWrapsElement != null) { argAsObjectReference = argAsWrapsElement.WrappedElement as IWebDriverObjectReference; } 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 (argAsObjectReference != null) { // TODO: Remove "ELEMENT" addition when all remote ends are spec-compliant. Dictionary <string, object> webDriverObjectReferenceDictionary = argAsObjectReference.ToDictionary(); converted = webDriverObjectReferenceDictionary; } 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(), nameof(arg)); } return(converted); }
private Dictionary <string, object> ConvertElement() { IWebDriverObjectReference elementReference = this.target as IWebDriverObjectReference; if (elementReference == null) { IWrapsElement elementWrapper = this.target as IWrapsElement; if (elementWrapper != null) { elementReference = elementWrapper.WrappedElement as IWebDriverObjectReference; } } if (elementReference == null) { throw new ArgumentException("Target element cannot be converted to IWebElementReference"); } Dictionary <string, object> elementDictionary = elementReference.ToDictionary(); return(elementDictionary); }