Esempio n. 1
0
        /// <inheritdoc />
        public string GetJavaScriptElementReference()
        {
            if (string.IsNullOrEmpty(_javascriptElementReference))
            {
                _javascriptElementReference = IEUtils.IEVariableNameHelper.CreateVariableName();
            }

            var originalId = GetWithFailOver(() => AsHtmlElement.id);

            AsHtmlElement.id = _javascriptElementReference;

            var scriptCode = string.Format("var {0} = document.getElementById('{0}');", _javascriptElementReference);

            IEUtils.RunScript(scriptCode, ParentWindow);

            AsHtmlElement.id = originalId;

            return(_javascriptElementReference);
        }
Esempio n. 2
0
        /// <summary>
        /// Fires the given event on the given element.
        /// </summary>
        /// <param name="eventName">Name of the event to fire</param>
        /// <param name="eventProperties">The event object properties.</param>
        public void FireEvent(string eventName, NameValueCollection eventProperties)
        {
            if (eventName == "onKeyPress" && eventProperties != null)
            {
                var keys = eventProperties.GetValues("keyCode");
                if (keys != null && keys.Length > 0)
                {
                    var addChar  = keys[0];
                    var newValue = _ieElement.GetAttributeValue("value") + ((char)int.Parse(addChar));
                    _ieElement.SetAttributeValue("value", newValue);
                }
            }

            var scriptCode = CreateJavaScriptFireEventCode(eventProperties, eventName);

            try
            {
                var window = _ieElement.ParentWindow;
                IEUtils.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)_ieElement.AsHtmlElement.document).CreateEventObject(ref prototypeEvent);

                for (var index = 0; index < eventProperties.Count; index++)
                {
                    var property = eventProperties.GetKey(index);
                    var value    = eventProperties.GetValues(index)[0];

                    ((IHTMLEventObj2)eventObj).setAttribute(property, value, 0);
                }

                _ieElement.AsDispHTMLBaseElement.FireEvent(eventName, ref eventObj);
            }
        }
Esempio n. 3
0
        public void ExecuteScript(string code)
        {
            var window = _ieElement.ParentWindow;

            IEUtils.RunScript(code, window);
        }
Esempio n. 4
0
 public void FireEvent()
 {
     IEUtils.RunScript(_scriptCode, _window);
 }
Esempio n. 5
0
 public void RunScript(string scriptCode, string language)
 {
     Logger.LogDebug(scriptCode);
     IEUtils.RunScript(scriptCode, language, htmlDocument.parentWindow);
 }