Esempio n. 1
0
        protected override void Execute(CodeActivityContext context)
        {
            string attribute_str   = Attribute.Get(context);
            string attribute_value = Value.Get(context);

            try
            {
                Int32 _timeout = TimeoutMS.Get(context);
                Thread.Sleep(_timeout);
                latch = new CountdownEvent(1);
                Thread td = new Thread(() =>
                {
                    if (Selector.Expression == null)
                    {
                        //ActiveElement处理
                    }
                    else
                    {
                        var selStr        = Selector.Get(context);
                        UiElement element = GetValueOrDefault(context, this.Element, null);
                        if (element == null && selStr != null)
                        {
                            element = UiElement.FromSelector(selStr);
                        }
                        if (element != null)
                        {
                            element.SetForeground();
                            mshtml.IHTMLDocument2 currDoc      = null;
                            SHDocVw.InternetExplorer ieBrowser = GetIEFromHWndClass.GetIEFromHWnd((int)element.WindowHandle, out currDoc);
                            mshtml.IHTMLElement currEle        = GetIEFromHWndClass.GetEleFromDoc(
                                element.GetClickablePoint(), (int)element.WindowHandle, currDoc);
                            currEle.setAttribute(attribute_str, attribute_value);
                        }
                        else
                        {
                            UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound"));
                        }
                    }
                    refreshData(latch);
                });
                td.TrySetApartmentState(ApartmentState.STA);
                td.IsBackground = true;
                td.Start();
                latch.Wait();
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "出现异常", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
            }
        }
Esempio n. 2
0
        protected override void Execute(NativeActivityContext context)
        {
            try
            {
                Int32 _timeout = TimeoutMS.Get(context);
                Thread.Sleep(_timeout);
                latch = new CountdownEvent(1);
                Thread td = new Thread(() =>
                {
                    if (Selector.Expression == null)
                    {
                        Browser getBrowser = currBrowser.Get(context);
                        if (getBrowser != null)
                        {
                            if (getBrowser.getIEBrowser() != null)
                            {
                                if (UiBrowser != null)
                                {
                                    UiBrowser.Set(context, getBrowser);
                                }
                            }
                            context.ScheduleAction(Body, getBrowser, OnCompleted, OnFaulted);
                        }
                    }
                    else
                    {
                        var allBrowsers = new SHDocVw.ShellWindows();
                        switch (BrowserType)
                        {
                        case BrowserTypes.IE:
                            {
                                var selStr        = Selector.Get(context);
                                UiElement element = UiElement.FromSelector(selStr);
                                IntPtr handle     = IntPtr.Zero;
                                if (element != null)
                                {
                                    handle = element.WindowHandle;
                                }

                                mshtml.IHTMLDocument2 currDoc      = null;
                                SHDocVw.InternetExplorer ieBrowser = GetIEFromHWndClass.GetIEFromHWnd((int)handle, out currDoc);
                                Browser thisBrowser = new Browser();
                                thisBrowser.SetIEBrowser(ieBrowser);
                                if (UiBrowser != null)
                                {
                                    UiBrowser.Set(context, thisBrowser);
                                }

                                ArrayList list      = new ArrayList();
                                var allShellWindows = new SHDocVw.ShellWindows();
                                foreach (SHDocVw.InternetExplorer browser in allShellWindows)
                                {
                                    list.Add(browser);
                                }
                                CommonVariable.BrowsersList = list;

                                context.ScheduleAction(Body, thisBrowser);
                                break;
                            }

                        case BrowserTypes.Chrome:
                            {
                                break;
                            }

                        case BrowserTypes.Firefox:
                            {
                                break;
                            }

                        default:
                            break;
                        }
                    }

                    refreshData(latch);
                });
                td.TrySetApartmentState(ApartmentState.STA);
                td.IsBackground = true;
                td.Start();
                latch.Wait();
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "出现异常", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
            }
        }