/// <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); } } }
// SPY FUNCTION public void Spy() { IntPtr hWnd = flexProc[0].MainWindowHandle; if (hWnd != IntPtr.Zero) { SetForegroundWindow(hWnd); ShowWindow(hWnd, SW_MAXIMIZE); } App = Gu.Wpf.UiAutomation.Application.Attach(flexProc[0].Id); MainWindow = App.MainWindow; Element = MainWindow.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.FrameworkIdProperty, "WPF")); try { //Clear SpyIMG files deletefiles(); var curtime = DateTime.Now; var day = curtime.Day; var month = curtime.Month; var year = curtime.Year; var sec = curtime.Second; var hour = curtime.Hour; var minute = curtime.Minute; var longTimeString = DateTime.Now.ToOADate(); var reformat = day + "-" + month + "-" + year + "__" + hour + "-" + minute + "-" + sec + "-"; using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\" + SR.username + @"\Documents\GUWPF\" + reformat + "SpyResult.json")) { this.WindowState = FormWindowState.Minimized; Thread.Sleep(500); SR.currenttime = longTimeString.ToString(); id = 0; foreach (UiElement UIE in Element) { if (!UIE.Bounds.IsEmpty) { SR.index = id; SR.autoDI = UIE.AutomationId; SR.classname = UIE.ClassName; SR.name = UIE.Name; SR.directory = @"C:\Users\" + SR.username + @"\Documents\GUWPF\SpyIMG\" + SR.index + " - " + SR.classname + ".png"; //SR.currenttime = curtime.ToString(); if (UIE.AutomationId == "") SR.autoDI = "No AutomationID"; if (UIE.Name == "") SR.name = "No Name"; UIE.CaptureToFile(@"C:\Users\" + SR.username + @"\Documents\GUWPF\SpyIMG\" + SR.index + " - " + SR.classname + ".png"); id++; listBox1.Items.Add("ID: " + SR.index + " - " + SR.autoDI + " - " + SR.classname + " - " + SR.name); string ObjectUI = JsonConvert.SerializeObject(SR, Newtonsoft.Json.Formatting.Indented); if (SR.index == 0) { file.WriteLine("["); file.WriteLine(ObjectUI + ","); } else if (SR.index == Element.Count - 1) { file.WriteLine(ObjectUI); file.WriteLine("]"); } else file.WriteLine(ObjectUI + ","); } } file.WriteLine("]"); this.WindowState = FormWindowState.Normal; } } catch (Exception err) { listBox1.Items.Add(id + " - " + SR.classname + " - " + err.Message); } }