/// <summary> /// Clear the value of textboxes or any control type with Edit /// </summary> /// <param name="Proc"></param> public static void ClearValue(string Proc) { var curtime = DateTime.Now; ExceptionCode excode = new ExceptionCode(); try { log.Info("BEGIN CLEAR VALUE"); Process targetProcess = WindowInteraction.GetProcess(Proc); GrabAUT.GetMainWindow(); WindowInteraction.FocusWindow(targetProcess); ElementListWPF = GrabAUT.SearchbyFramework("WPF"); //ElementListWin32 = DoSpy.SearchbyFramework("Win32"); //if (ElementListWin32[0].AsMessageBox().) //{ // ElementListWin32[0].AsMessageBox().Close(); //} int id = 0; foreach (UiElement UIE in ElementListWPF) { if (UIE.ControlType.ProgrammaticName == "ControlType.Edit" && UIE.AsTextBox().IsEnabled) { if (!UIE.AsTextBox().IsReadOnly) { //UIE.AsTextBox().Enter(""); (UIE.AutomationElement.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern).SetValue(""); log.Info(id + " CLEARED"); } } else if (UIE.ClassName == "CheckBox") { if (UIE.AsCheckBox().IsChecked == true) { UIE.AsCheckBox().Click(); log.Info(id + " UNCHECKED"); } } id++; } } catch (Exception ex) { if (ex.HResult == excode.INVALID_SCRIPT) { log.Error("CANNOT USE THE CURRENT SCRIPT ON THIS SCREEN"); } else { log.Error(ex.Message); } } }
public static void GetMainWindow() { try { Process AttachProcess = WindowInteraction.GetProcess(ProcessForm.targetproc); App = Application.Attach(AttachProcess.Id); MainWindow = App.MainWindow; } catch { throw new Exception("Cannot found MainWindow"); //System.Windows.Forms.MessageBox.Show("CANNOT ATTACH THIS PROCESS"); } }
public static void GetMainWindow() { try { Process AttachProcess = WindowInteraction.GetProcess(ProcessForm.targetproc); App = Application.Attach(AttachProcess.Id); App.GetMainWindow(TimeSpan.FromSeconds(5)); MainWindow = App.MainWindow; } catch { //T1.Join(); throw new Exception("Cannot get MainWindow"); } }
public static void GetMainWindow() { try { Process AttachProcess = WindowInteraction.GetProcess(ProcessForm.targetproc); Application.WaitForMainWindow(AttachProcess, TimeSpan.FromSeconds(1)); App = Application.Attach(AttachProcess.Id); MainWindow = App.MainWindow; } catch { //T1.Join(); throw new Exception("This process cannot be attached"); } }
public static void DoCapture(string Proc) { var curtime = DateTime.Now; var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); var imagePath = path + @"\Botsina\SpyObjects\"; System.IO.FileInfo file = new System.IO.FileInfo(imagePath); if (file.Directory.Exists) { DirectoryInfo dir = new DirectoryInfo(imagePath); foreach (FileInfo fi in dir.GetFiles()) { fi.Delete(); } } else { file.Directory.Create(); } try { //this.Hide(); log.Info("BEGIN CAPTURE TO FILE"); file.Directory.Create(); Process targetProcess = WindowInteraction.GetProcess(Proc); App = Gu.Wpf.UiAutomation.Application.Attach(targetProcess.Id); MainWindow = App.MainWindow; ElementList = MainWindow.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.FrameworkIdProperty, "WPF")); SpyObjectList = new SpyObject[ElementList.Count]; int SpyObjectIndex = 0; SendKeys.Send("{PRTSC}"); Image img = Clipboard.GetImage(); for (int i = 0; i < ElementList.Count; i++) { SpyObjectList[SpyObjectIndex] = new SpyObject(); SpyObjectList[SpyObjectIndex].index = SpyObjectIndex; if (ElementList[i].AutomationId == "" && SpyObjectIndex - 1 > 0 && ElementList[i - 1].Name != "" && ElementList[i].Name == "") { SpyObjectList[SpyObjectIndex].automationId = (ElementList[i - 1].Name + "_" + ElementList[i].ClassName).Replace(" ", "_").Replace(":", ""); } else { SpyObjectList[SpyObjectIndex].automationId = ElementList[i].AutomationId; } SpyObjectList[SpyObjectIndex].name = ElementList[i].Name; SpyObjectList[SpyObjectIndex].type = ElementList[i].ClassName; if ((SpyObjectList[SpyObjectIndex].type == "ComboBox" || SpyObjectList[SpyObjectIndex].type == "ComboBoxEdit" || SpyObjectList[SpyObjectIndex].type == "DataGrid" || SpyObjectList[SpyObjectIndex].type == "TextBox" || SpyObjectList[SpyObjectIndex].type == "Button" || SpyObjectList[SpyObjectIndex].type == "RadioButton" || SpyObjectList[SpyObjectIndex].type == "AutoCompleteCombobox") && SpyObjectList[SpyObjectIndex].automationId.Contains("PART") != true) { if (ElementList[SpyObjectIndex].Bounds.IsEmpty == false && ElementList[SpyObjectIndex].IsOffscreen == false) { ElementList[SpyObjectIndex].CaptureToFile(imagePath + SpyObjectIndex + ".png"); log.Info(ElementList[SpyObjectIndex].ClassName); } } SpyObjectIndex++; } img.Save(imagePath + "thisScreen" + ".png"); log.Info("DONE CAPTURE TO FILE"); //this.Show(); } catch (Exception ex) { log.Error("ERROR CODE: " + ex.HResult + " ----- " + "detail: " + ex.Message); //this.Show(); } }