public override EnumActionResult Execute() { string searchType = _vm.variables.Get(m_params[1]); string value = _vm.variables.Get(m_params[3]); AutomationElement button = null; AutomationElement aeTarget = _vm.host.TargetWindow; switch (searchType) { case "ByID": button = Finder.GetButtonByID(aeTarget, value); break; case "ByName": button = Finder.GetButtonByName(aeTarget, value); break; default: _vm.host.WriteLog(m_type + " Unrecognized Search Type: '" + searchType + "'"); return(EnumActionResult.ERROR); } if (null == button) { _vm.PushError("Button '" + value + "' NOT found on '" + aeTarget.Current.Name + "'."); return(EnumActionResult.ERROR); } _vm.host.WriteLog("Button '" + value + "' found on '" + aeTarget.Current.Name + "'."); _vm.host.aeCurrent = button; return(EnumActionResult.OK); }
public override EnumActionResult Execute() { AutomationElement button = null; int count = 0; string button2Find = _vm.variables.Get(m_params[3]); int maxAttempt = Convert.ToInt32(_vm.variables.Get(m_params[5])); bool bFindByID = false; string str = _vm.variables.Get(m_params[1]); switch (str) { case "ByID": bFindByID = true; break; case "ByName": bFindByID = false; break; default: UtilSys.MessageBoxError("ActionWait4Button::Execute -> Unrecognized SearchBy Type [" + str + "]"); return(EnumActionResult.ERROR); } do { _vm.host.DoEvents(); if (VMStatus.IN_PLAYBACK != _vm.PlaybackStatus) { return(EnumActionResult.STOPPED); } _vm.host.WriteLog("TargetWindowTitle: " + _vm.host.TargetWindowTitle); _vm.host.TargetWindow = Finder.GetTopLevelWindow(_vm.host.TargetWindowTitle); if (null != _vm.host.TargetWindow) { if (bFindByID) { button = Finder.GetButtonByID(_vm.host.TargetWindow, button2Find); } else { button = Finder.GetButtonByName(_vm.host.TargetWindow, button2Find); } _vm.host.WriteLog("Try to find button: '" + button2Find + "'"); if (null != button) { _vm.host.WriteLog("Button '" + button2Find + "' found. (" + maxAttempt + "/" + count + ")"); _vm.host.aeCurrent = button; return(EnumActionResult.OK); } else { _vm.host.WriteLog("Button '" + button2Find + "' NOT found. (" + maxAttempt + "/" + count + ")"); } ++count; } UtilSys.Wait(1000); } while (count < maxAttempt); return(EnumActionResult.TIMEOUT); // bad things happen here! }