private void CollectInternetExplorerInstances()
        {
            var enumerator = new WindowsEnumerator();
            _browsers = new List<IWebBrowser2>();

            var topLevelWindows = enumerator.GetTopLevelWindows("IEFrame");
            foreach (var mainBrowserWindow in topLevelWindows)
            {
                var windows = enumerator.GetChildWindows(mainBrowserWindow.Hwnd, "TabWindowClass");

                // IE6 has no TabWindowClass so use the IEFrame as starting point
                if (windows.Count == 0)
                {
                    windows.Add(mainBrowserWindow);
                }

                foreach (var window in windows)
                {
                    var hwnd = window.Hwnd;
                    var document2 = UtilityClass.TryFuncIgnoreException(() => IEUtils.IEDOMFromhWnd(hwnd));
                    if (document2 == null) continue;

                    var parentWindow = UtilityClass.TryFuncIgnoreException(() => document2.parentWindow);
                    if (parentWindow == null) continue;

                    var webBrowser2 = UtilityClass.TryFuncIgnoreException(() => RetrieveIWebBrowser2FromIHtmlWindw2Instance(parentWindow));
                    if (webBrowser2 == null) continue;

                    _browsers.Add(webBrowser2);
                }
            }
        }
        public static IWebBrowser2 GetFrameFromHTMLDocument(int frameIndex, HTMLDocument htmlDocument)
        {
            var processor = new FrameByIndexProcessor(frameIndex, htmlDocument);

            IEUtils.EnumIWebBrowser2Interfaces(processor);

            return(processor.IWebBrowser2());
        }
Esempio n. 3
0
        internal static int GetFrameCountFromHTMLDocument(HTMLDocument htmlDocument)
        {
            var processor = new FrameCountProcessor(htmlDocument);

            IEUtils.EnumIWebBrowser2Interfaces(processor);

            return(processor.FramesCount);
        }
Esempio n. 4
0
        /// <inheritdoc />
        public void FireEventNoWait(string eventName, NameValueCollection eventProperties)
        {
            var scriptCode = IEUtils.CreateJavaScriptFireEventCode(eventProperties, AsDispHTMLBaseElement, eventName);

            var asyncScriptRunner = new AsyncScriptRunner(scriptCode.ToString(), ParentWindow);

            UtilityClass.AsyncActionOnBrowser(asyncScriptRunner.FireEvent);
        }
Esempio n. 5
0
        private static bool DialogBelongsToIEWindowForIe8AndHigher(Window dialog, Window mainWindow)
        {
            Logger.LogDebug("Main: " + mainWindow.Hwnd + ", " + mainWindow.Title + ", " + mainWindow.ProcessID);

            var hWnd    = IEUtils.GetInteretExplorerServerHwnd(mainWindow.Hwnd);
            var window1 = new Window(hWnd);

            Logger.LogDebug("IES: " + window1.Hwnd + ", " + window1.Title + ", " + window1.ProcessID);

            return(window1.ProcessID == dialog.ProcessID);
        }
Esempio n. 6
0
        /// <inheritdoc />
        public void FireEvent(string eventName, NameValueCollection eventProperties)
        {
            if (eventProperties == null)
            {
                IEUtils.FireEvent(AsDispHTMLBaseElement, eventName);
            }
            else
            {
                if (eventName == "onKeyPress")
                {
                    var addChar  = eventProperties.GetValues("keyCode")[0];
                    var newValue = GetAttributeValue("value") + ((char)int.Parse(addChar));
                    SetAttributeValue("value", newValue);
                }

                IEUtils.FireEvent(AsDispHTMLBaseElement, eventName, eventProperties);
            }
        }
Esempio n. 7
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. 8
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. 9
0
        public void ExecuteScript(string code)
        {
            var window = _ieElement.ParentWindow;

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