/// <summary> /// Triggers the element via the Angular function "trigger". /// </summary> protected void TriggerElement() { if (Browser.JavascriptLibraries.Contains(JavaScriptLibrary.Angular)) { Browser.ExecuteScript("angular.element(document.querySelector('#" + Id + "')).triggerHandler('input');", false); } }
/// <summary> /// Sets an attribute value by the provided name. /// </summary> /// <param name="name"> The name of the attribute to write. </param> /// <param name="value"> The value to be written. </param> public void SetAttributeValue(string name, string value) { name = _propertiesToRename.ContainsKey(name) ? _propertiesToRename[name] : name; value = value.Replace("\r", "\\r") .Replace("\n", "\\n"); var script = "TestR.setElementValue('" + Id + "','" + name + "','" + value + "')"; Browser.ExecuteScript(script); AddOrUpdateElementAttribute(name, value); TriggerElement(); }
/// <summary> /// Fires an event on the element. /// </summary> /// <param name="eventName"> The events name to fire. </param> /// <param name="eventProperties"> The properties for the event. </param> public void FireEvent(string eventName, Dictionary <string, string> eventProperties) { var values = eventProperties.Aggregate("", (current, item) => current + ("{ key: '" + item.Key + "', value: '" + item.Value + "'},")); if (values.Length > 0) { values = values.Remove(values.Length - 1, 1); } var script = "TestR.triggerEvent(document.getElementById('" + Id + "'), '" + eventName.ToLower() + "', [" + values + "]);"; Browser.ExecuteScript(script); }
/// <summary> /// Gets an attribute value by the provided name. /// </summary> /// <param name="name"> The name of the attribute to read. </param> /// <param name="refresh"> A flag to force the element to refresh. </param> /// <returns> The attribute value. </returns> public string GetAttributeValue(string name, bool refresh) { string value; if (refresh) { name = _propertiesToRename.ContainsKey(name) ? _propertiesToRename[name] : name; var script = "TestR.getElementValue('" + Id + "','" + name + "')"; value = Browser.ExecuteScript(script); } else { value = GetCachedAttribute(name); } if (string.IsNullOrWhiteSpace(value)) { return(string.Empty); } SetElementAttributeValue(name, value); return(value); }
/// <summary> /// Gets Raw Html. /// </summary> public string Html() { return(Browser.ExecuteScript("document.getElementById('" + Id + "').innerHTML")); }
/// <summary> /// Focuses on the element. /// </summary> public void Focus() { Browser.ExecuteScript("document.getElementById('" + Id + "').focus()"); }
/// <summary> /// Clicks the element. /// </summary> public void Click() { Browser.ExecuteScript("document.getElementById('" + Id + "').click()"); }