/// <summary> /// Fires the given event on the given element. /// </summary> /// <param name="element">Element to fire the event on</param> /// <param name="eventName">Name of the event to fire</param> public virtual void FireEvent(DispHTMLBaseElement element, string eventName) { // TODO: Passing the eventarguments in a new param of type array. This array // holds 0 or more name/value pairs where the name is a property of the event object // and the value is the value that's assigned to the property. // Execute the JScript to fire the event inside the Browser. string scriptCode = "var newEvt = document.createEventObject();"; scriptCode += "newEvt.button = 1;"; scriptCode += "document.getElementById('" + element.uniqueID + "').fireEvent('" + eventName + "', newEvt);"; try { RunScript(scriptCode); } catch (RunScriptException) { // In a cross domain automation scenario a System.UnauthorizedAccessException // is thrown. The following code works, but setting the event properties // has no effect so that is left out. object dummyEvt = null; // IHTMLEventObj2 mouseDownEvent = (IHTMLEventObj2)parentEvt; // mouseDownEvent.button = 1; object parentEvt = ((IHTMLDocument4)element.document).CreateEventObject(ref dummyEvt); element.FireEvent(eventName, ref parentEvt); } }
/// <summary> /// Fires the given event on the given element. /// </summary> /// <param name="element">Element to fire the event on</param> /// <param name="eventName">Name of the event to fire</param> /// <param name="eventObjectProperties">The event object properties.</param> public static void FireEvent(DispHTMLBaseElement element, string eventName, NameValueCollection eventObjectProperties) { var scriptCode = CreateJavaScriptFireEventCode(eventObjectProperties, element, eventName); try { var window = ((IHTMLDocument2)element.document).parentWindow; RunScript(scriptCode, window); } catch (RunScriptException) { // In a cross domain automation scenario a System.UnauthorizedAccessException // is thrown. This code does cause the registered client event handlers to be fired // but it does not deliver the event to the control itself. Consequently the // control state may need to be updated directly (eg. as with key press event). object prototypeEvent = null; object eventObj = ((IHTMLDocument4)element.document).CreateEventObject(ref prototypeEvent); for (var index = 0; index < eventObjectProperties.Count; index++) { var property = eventObjectProperties.GetKey(index); var value = eventObjectProperties.GetValues(index)[0]; ((IHTMLEventObj2)eventObj).setAttribute(property, value, 0); } element.FireEvent(eventName, ref eventObj); } }
/// <summary> /// Fires the given event on the given element. /// </summary> /// <param name="element">Element to fire the event on</param> /// <param name="eventName">Name of the event to fire</param> /// <param name="eventObjectProperties">The event object properties.</param> public static void FireEvent(DispHTMLBaseElement element, string eventName, NameValueCollection eventObjectProperties) { StringBuilder scriptCode = CreateJavaScriptFireEventCode(eventObjectProperties, element, eventName); try { IHTMLWindow2 window = ((IHTMLDocument2)element.document).parentWindow; RunScript(scriptCode.ToString(), window); } catch (RunScriptException) { // In a cross domain automation scenario a System.UnauthorizedAccessException // is thrown. The following code doesn't seem to have any effect, // but maybe someday MicroSoft fixes the issue... so I wrote the code anyway. object dummyEvt = null; object parentEvt = ((IHTMLDocument4)element.document).CreateEventObject(ref dummyEvt); IHTMLEventObj2 eventObj = (IHTMLEventObj2)parentEvt; for (int index = 0; index < eventObjectProperties.Count; index++) { string property = eventObjectProperties.GetKey(index); string value = eventObjectProperties.GetValues(index)[0]; eventObj.setAttribute(property, value, 0); } element.FireEvent(eventName, ref parentEvt); } }
/// <summary> /// Fires the given event on the given element. /// </summary> /// <param name="element">Element to fire the event on</param> /// <param name="eventName">Name of the event to fire</param> public static void FireEvent(DispHTMLBaseElement element, string eventName) { NameValueCollection collection = new NameValueCollection(); collection.Add("button", "1"); FireEvent(element, eventName, collection); }
/// <summary> /// Fires the given event on the given element. /// </summary> /// <param name="element">Element to fire the event on</param> /// <param name="eventName">Name of the event to fire</param> public static void FireEvent(DispHTMLBaseElement element, string eventName) { var collection = new NameValueCollection { { "button", "1" } }; FireEvent(element, eventName, collection); }
/// <summary> /// Fires the given event on the given element. /// </summary> /// <param name="element">Element to fire the event on</param> /// <param name="eventName">Name of the event to fire</param> public virtual void FireEvent(DispHTMLBaseElement element, string eventName) { UtilityClass.FireEvent(element, eventName); }
public static StringBuilder CreateJavaScriptFireEventCode(NameValueCollection eventObjectProperties, DispHTMLBaseElement element, string eventName) { StringBuilder scriptCode = new StringBuilder(); scriptCode.Append("var newEvt = document.createEventObject();"); CreateJavaScriptEventObject(scriptCode, eventObjectProperties); scriptCode.Append("document.getElementById('" + element.uniqueID + "').fireEvent('" + eventName + "', newEvt);"); return(scriptCode); }
public static StringBuilder CreateJavaScriptFireEventCode(NameValueCollection eventObjectProperties, DispHTMLBaseElement element, string eventName) { var scriptCode = new StringBuilder(); scriptCode.Append("var newEvt = document.createEventObject();"); CreateJavaScriptEventObject(scriptCode, eventObjectProperties); var originalId = UtilityClass.TryFuncFailOver(() => element.id, 25, 10); var variableName = IEVariableNameHelper.CreateVariableName(); element.id = variableName; scriptCode.Append(string.Format("var {0} = document.getElementById('{0}');", variableName)); scriptCode.Append(string.Format("{0}.id = '{1}';", variableName, originalId)); scriptCode.Append(string.Format("{0}.fireEvent('{1}', newEvt);", variableName, eventName)); return scriptCode; }
public static StringBuilder CreateJavaScriptFireEventCode(NameValueCollection eventObjectProperties, DispHTMLBaseElement element, string eventName) { var scriptCode = new StringBuilder(); scriptCode.Append("var newEvt = document.createEventObject();"); CreateJavaScriptEventObject(scriptCode, eventObjectProperties); var originalId = UtilityClass.TryFuncFailOver(() => element.id, 25, 10); var variableName = IEVariableNameHelper.CreateVariableName(); element.id = variableName; scriptCode.Append(string.Format("var {0} = document.getElementById('{0}');", variableName)); scriptCode.Append(string.Format("{0}.id = '{1}';", variableName, originalId)); scriptCode.Append(string.Format("{0}.fireEvent('{1}', newEvt);", variableName, eventName)); return(scriptCode); }
public static StringBuilder CreateJavaScriptFireEventCode(NameValueCollection eventObjectProperties, DispHTMLBaseElement element, string eventName) { StringBuilder scriptCode = new StringBuilder(); scriptCode.Append("var newEvt = document.createEventObject();"); CreateJavaScriptEventObject(scriptCode, eventObjectProperties); scriptCode.Append("document.getElementById('" + element.uniqueID + "').fireEvent('" + eventName + "', newEvt);"); return scriptCode; }
/// <summary> /// Fires the given event on the given element. /// </summary> /// <param name="element">Element to fire the event on</param> /// <param name="eventName">Name of the event to fire</param> /// <param name="eventObjectProperties">The event object properties.</param> public static void FireEvent(DispHTMLBaseElement element, string eventName, NameValueCollection eventObjectProperties) { StringBuilder scriptCode = CreateJavaScriptFireEventCode(eventObjectProperties, element, eventName); try { IHTMLWindow2 window = ((IHTMLDocument2) element.document).parentWindow; RunScript(scriptCode.ToString(), window); } catch (RunScriptException) { // In a cross domain automation scenario a System.UnauthorizedAccessException // is thrown. The following code doesn't seem to have any effect, // but maybe someday MicroSoft fixes the issue... so I wrote the code anyway. object dummyEvt = null; object parentEvt = ((IHTMLDocument4) element.document).CreateEventObject(ref dummyEvt); IHTMLEventObj2 eventObj = (IHTMLEventObj2) parentEvt; for (int index = 0; index < eventObjectProperties.Count; index++) { string property = eventObjectProperties.GetKey(index); string value = eventObjectProperties.GetValues(index)[0]; eventObj.setAttribute(property, value, 0); } element.FireEvent(eventName, ref parentEvt); } }