protected override void Execute(CodeActivityContext context) { Int32 _delayAfter = GetValueOrDefault(context, this.DelayAfter, 3000); Int32 _delayBefore = GetValueOrDefault(context, this.DelayBefore, 2000); try { Thread.Sleep(_delayBefore); var selStr = Selector.Get(context); UiElement element = GetValueOrDefault(context, this.Element, null); if (element == null && selStr != null) { element = UiElement.FromSelector(selStr); } Int32 pointX = 0; Int32 pointY = 0; if (element != null) { pointX = element.GetClickablePoint().X; pointY = element.GetClickablePoint().Y; element.SetForeground(); element.Focus(); } else { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", "查找不到元素"); if (ContinueOnError.Get(context)) { return; } else { throw new NotImplementedException("查找不到元素"); } } Thread.Sleep(_delayAfter); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "设置键盘焦点失败", e.Message); if (ContinueOnError.Get(context)) { } else { throw; } } }
protected override void Execute(CodeActivityContext context) { Int32 _delayAfter = GetValueOrDefault(context, this.DelayAfter, 3000); Int32 _delayBefore = GetValueOrDefault(context, this.DelayBefore, 2000); try { Thread.Sleep(_delayBefore); var selStr = Selector.Get(context); UiElement element = GetValueOrDefault(context, this.Element, null); if (element == null && selStr != null) { element = UiElement.FromSelector(selStr); } Int32 pointX = 0; Int32 pointY = 0; if (element != null) { pointX = element.GetClickablePoint().X; pointY = element.GetClickablePoint().Y; element.SetForeground(); element.Focus(); } else { UIAutomationCommon.HandleContinueOnError(context, ContinueOnError, Localize.LocalizedResources.GetString("msgNoElementFound")); } Thread.Sleep(_delayAfter); } catch (Exception e) { SharedObject.Instance.Output(SharedObject.enOutputType.Error, "设置键盘焦点失败", e.Message); if (ContinueOnError.Get(context)) { } else { throw; } } }