private static object ConvertObjectToJavaScriptObject(object arg) { IWrapsElement argAsWrapsElement = arg as IWrapsElement; RemoteWebElement argAsElement = arg as RemoteWebElement; IEnumerable argAsEnumerable = arg as IEnumerable; IDictionary argAsDictionary = arg as IDictionary; 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) { // TODO: Remove addition of 'id' key when spec is changed. Dictionary <string, object> elementDictionary = new Dictionary <string, object>(); elementDictionary.Add("ELEMENT", argAsElement.InternalElementId); elementDictionary.Add("id", argAsElement.InternalElementId); 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); }
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); }
/// <summary> /// Compares if two elements are equal /// </summary> /// <param name="obj">Object to compare against</param> /// <returns>A boolean if it is equal or not</returns> public override bool Equals(object obj) { IWebElement other = obj as IWebElement; if (other == null) { return(false); } IWrapsElement objAsWrapsElement = obj as IWrapsElement; if (objAsWrapsElement != null) { other = objAsWrapsElement.WrappedElement; } RemoteWebElement otherAsElement = other as RemoteWebElement; if (otherAsElement == null) { return(false); } if (this.elementId == otherAsElement.Id) { // For drivers that implement ID equality, we can check for equal IDs // here, and expect them to be equal. There is a potential danger here // where two different elements are assigned the same ID. return(true); } if (!driver.IsSpecificationCompliant) { try { Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("id", this.Id); parameters.Add("other", otherAsElement.Id); Response response = this.Execute(DriverCommand.ElementEquals, parameters); object value = response.Value; return(value != null && value is bool && (bool)value); } catch (NotImplementedException) { } } return(false); }
/// <summary> /// Creates a <see cref="RemoteWebElement"/> with the specified ID. /// </summary> /// <param name="elementId">The ID of this element.</param> /// <returns>A <see cref="RemoteWebElement"/> with the specified ID.</returns> protected virtual RemoteWebElement CreateElement(string elementId) { RemoteWebElement toReturn; if (capabilities.IsJavaScriptEnabled) { toReturn = new RenderedRemoteWebElement(this, elementId); } else { toReturn = new RemoteWebElement(this, elementId); } return(toReturn); }
//public WebElementDecorator(IWebElement realWebElement) //public WebElementDecorator(RemoteWebElement realWebElement) // : base(realWebElement.WrappedDriver, "") public WebElementDecorator(RemoteWebElement realWebElement) { this.DecoratedWebElement = realWebElement; // as RemoteWebElement; Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<WebElementDecorator(IWebElement realWebElement): " + this.DecoratedWebElement.ToString()); Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<WebElementDecorator(IWebElement realWebElement): " + this.DecoratedWebElement.GetType().Name); try { //Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<WebElementDecorator(IWebElement realWebElement): " + this.DecoratedWebElement.TagName); Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<WebElementDecorator(IWebElement realWebElement): " + this.DecoratedWebElement.TagName); } catch (Exception eTagName) { Console.WriteLine(eTagName.Message); Console.WriteLine(eTagName.GetType().Name); } Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<WebElementDecorator(IWebElement realWebElement): OK"); this.SearchHistory = new List<ISearchHistory>(); }
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); }
/// <summary> /// Find the element in the response /// </summary> /// <param name="response">Response from the browser</param> /// <returns>Element from the page</returns> internal IWebElement GetElementFromResponse(Response response) { if (response == null) { throw new NoSuchElementException(); } RemoteWebElement element = null; Dictionary<string, object> elementDictionary = response.Value as Dictionary<string, object>; if (elementDictionary != null) { string id = (string)elementDictionary["ELEMENT"]; element = this.CreateElement(id); } return element; }
/// <summary> /// Finds the elements that are in the response /// </summary> /// <param name="response">Response from the browser</param> /// <returns>Collection of elements</returns> internal ReadOnlyCollection<IWebElement> GetElementsFromResponse(Response response) { List<IWebElement> toReturn = new List<IWebElement>(); object[] elements = response.Value as object[]; foreach (object elementObject in elements) { Dictionary<string, object> elementDictionary = elementObject as Dictionary<string, object>; if (elementDictionary != null) { string id = (string)elementDictionary["ELEMENT"]; RemoteWebElement element = this.CreateElement(id); toReturn.Add(element); } } return toReturn.AsReadOnly(); }
private static object ConvertObjectToJavaScriptObject(object arg) { RemoteWebElement argAsElement = arg 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 { throw new ArgumentException("Argument is of an illegal type" + arg.ToString(), "arg"); } return(converted); }
/// <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"); } RemoteWebElement convertedElement = frameElement as RemoteWebElement; if (convertedElement == null) { throw new ArgumentException("frameElement cannot be converted to RemoteWebElement", "frameElement"); } Dictionary <string, object> elementDictionary = new Dictionary <string, object>(); elementDictionary.Add("ELEMENT", convertedElement.InternalElementId); Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("id", elementDictionary); this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters); return(this.driver); }
internal IWebElement GetElementFromResponse(Response response) { if (response == null) { throw new NoSuchElementException(); } RemoteWebElement result = null; Dictionary <string, object> dictionary = response.Value as Dictionary <string, object>; if (dictionary != null) { string elementId = string.Empty; if (dictionary.ContainsKey("element-6066-11e4-a52e-4f735466cecf")) { elementId = (string)dictionary["element-6066-11e4-a52e-4f735466cecf"]; } else if (dictionary.ContainsKey("ELEMENT")) { elementId = (string)dictionary["ELEMENT"]; } result = this.CreateElement(elementId); } return(result); }
/// <summary> /// Creates a <see cref="RemoteWebElement"/> with the specified ID. /// </summary> /// <param name="elementId">The ID of this element.</param> /// <returns>A <see cref="RemoteWebElement"/> with the specified ID.</returns> protected virtual RemoteWebElement CreateElement(string elementId) { RemoteWebElement toReturn = new RemoteWebElement(this, elementId); return toReturn; }
/// <summary> /// Initializes a new instance of the <see cref="RemoteCoordinates"/> class. /// </summary> /// <param name="element">The <see cref="RemoteWebElement"/> to be located.</param> public RemoteCoordinates(RemoteWebElement element) { this.element = element; }
/// <summary> /// Initializes a new instance of the <see cref="RemoteCoordinates"/> class. /// </summary> /// <param name="element">The <see cref="RemoteWebElement"/> to be located.</param> public RemoteCoordinates(RemoteWebElement element) { this.element = element; }
private void SetLocalFileDetector(RemoteWebElement element) { ((RemoteWebDriver)element.WrappedDriver).FileDetector = new LocalFileDetector(); }
/// <summary> /// Creates a <see cref="RemoteWebElement"/> with the specified ID. /// </summary> /// <param name="elementId">The ID of this element.</param> /// <returns>A <see cref="RemoteWebElement"/> with the specified ID.</returns> protected virtual RemoteWebElement CreateElement(string elementId) { RemoteWebElement toReturn; if (this.capabilities.IsJavaScriptEnabled) { toReturn = new RenderedRemoteWebElement(this, elementId); } else { toReturn = new RemoteWebElement(this, elementId); } return toReturn; }
private object ParseJavaScriptReturnValue(object responseValue) { object returnValue = null; Dictionary <string, object> resultAsDictionary = responseValue as Dictionary <string, object>; object[] resultAsArray = responseValue as object[]; if (resultAsDictionary != null) { if (resultAsDictionary.ContainsKey("ELEMENT")) { string id = (string)resultAsDictionary["ELEMENT"]; RemoteWebElement element = this.CreateElement(id); returnValue = element; } else { // Recurse through the dictionary, re-parsing each value. string[] keyCopy = new string[resultAsDictionary.Keys.Count]; resultAsDictionary.Keys.CopyTo(keyCopy, 0); foreach (string key in keyCopy) { resultAsDictionary[key] = this.ParseJavaScriptReturnValue(resultAsDictionary[key]); } returnValue = resultAsDictionary; } } else if (resultAsArray != null) { bool allElementsAreWebElements = true; List <object> toReturn = new List <object>(); foreach (object item in resultAsArray) { object parsedItem = this.ParseJavaScriptReturnValue(item); IWebElement parsedItemAsElement = parsedItem as IWebElement; if (parsedItemAsElement == null) { allElementsAreWebElements = false; } toReturn.Add(parsedItem); } if (toReturn.Count > 0 && allElementsAreWebElements) { List <IWebElement> elementList = new List <IWebElement>(); foreach (object listItem in toReturn) { IWebElement itemAsElement = listItem as IWebElement; elementList.Add(itemAsElement); } returnValue = elementList.AsReadOnly(); } else { returnValue = toReturn.AsReadOnly(); } } else { returnValue = responseValue; } return(returnValue); }
private object ParseJavaScriptReturnValue(object responseValue) { Dictionary <string, object> dictionary = responseValue as Dictionary <string, object>; object[] array = responseValue as object[]; object result; if (dictionary != null) { if (dictionary.ContainsKey("element-6066-11e4-a52e-4f735466cecf")) { string elementId = (string)dictionary["element-6066-11e4-a52e-4f735466cecf"]; RemoteWebElement remoteWebElement = this.CreateElement(elementId); result = remoteWebElement; } else if (dictionary.ContainsKey("ELEMENT")) { string elementId2 = (string)dictionary["ELEMENT"]; RemoteWebElement remoteWebElement2 = this.CreateElement(elementId2); result = remoteWebElement2; } else { string[] array2 = new string[dictionary.Keys.Count]; dictionary.Keys.CopyTo(array2, 0); string[] array3 = array2; for (int i = 0; i < array3.Length; i++) { string key = array3[i]; dictionary[key] = this.ParseJavaScriptReturnValue(dictionary[key]); } result = dictionary; } } else if (array != null) { bool flag = true; List <object> list = new List <object>(); object[] array4 = array; for (int j = 0; j < array4.Length; j++) { object responseValue2 = array4[j]; object obj = this.ParseJavaScriptReturnValue(responseValue2); if (!(obj is IWebElement)) { flag = false; } list.Add(obj); } if (list.Count > 0 && flag) { List <IWebElement> list2 = new List <IWebElement>(); foreach (object current in list) { IWebElement item = current as IWebElement; list2.Add(item); } result = list2.AsReadOnly(); } else { result = list.AsReadOnly(); } } else { result = responseValue; } return(result); }
/// <summary> /// Creates a <see cref="RemoteWebElement"/> with the specified ID. /// </summary> /// <param name="elementId">The ID of this element.</param> /// <returns>A <see cref="RemoteWebElement"/> with the specified ID.</returns> protected virtual RemoteWebElement CreateElement(string elementId) { RemoteWebElement toReturn = new RemoteWebElement(this, elementId); return(toReturn); }
private RemoteWebElement CreateRemoteWebElement() { RemoteWebElement toReturn; if (capabilities.IsJavaScriptEnabled) { toReturn = new RenderedRemoteWebElement(); } else { toReturn = new RemoteWebElement(); } toReturn.Parent = this; return toReturn; }