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)) { } } }
protected override bool OnPerform(WatiN.Core.Element element) { if (autoSubmit) { element.Click(); } else { var nativeElement = element.NativeElement as IEElement; mshtml.IHTMLElement el = nativeElement.AsHtmlElement; el.setAttribute("__recordmark", RecordMark ? "1" : "0"); } return(true); }
//委托函数--输入密码并点击登录 private void InputPassword() { mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)web1.Document; mshtml.IHTMLElement password = (mshtml.IHTMLElement)doc.all.item("p", 0); password.setAttribute("value", str_pwd); }
//委托函数--输入QQ号码 private void InputQQ() { mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)web1.Document; mshtml.IHTMLElement usr = (mshtml.IHTMLElement)doc.all.item("u", 0); usr.setAttribute("value", str_qq); }