public static void OnMouseLeftClick(object sender, MouseEventArgs m) { #region XPath string labelText = string.Empty; Form1.textBox.Text = "Resolving Xpath"; Stopwatch s1 = new Stopwatch(); s1.Start(); Task resolveData = Task.Factory.StartNew(() => { System.Windows.Point point = new System.Windows.Point(m.X, m.Y); AutomationElement el = AutomationElement.FromPoint(point); var processExecutablePath = WinAPIs.GetMainModuleFilepath(el.Current.ProcessId); var processName = Process.GetProcessById(el.Current.ProcessId).ProcessName; WinAPIs w = new WinAPIs(); UIELementActivity u = new UIELementActivity(); var hWindow = WinAPIs.WindowFromPoint(m.Location); string clickedWindow = "Clicked window is : " + w.GetWindowText(hWindow); Console.WriteLine(clickedWindow); string rawXPath = string.Empty; string preparedXml = string.Empty; #region uncomment to get from c++ library //Stopwatch s = new Stopwatch(); //s.Start(); //rawXPath = w.GetUiXPath(m.X, m.Y); //s.Stop(); //Console.WriteLine("Elapsed Time is :" + s.ElapsedMilliseconds); //preparedXml = GenerateXPath.GetUITaskList(rawXPath); ////var xPath = GenerateXPath.GenerateXPathToUiElement(preparedXml); //labelText = clickedWindow + Environment.NewLine + String.Format("RawXPath is ={0}" + Environment.NewLine, preparedXml); #endregion #region own written code preparedXml = GenerateXPath.GetUITaskList(el); TrackedAction t1 = new TrackedAction { Id = Guid.NewGuid(), CreatedAt = DateTime.Now, IdentificationDetail = preparedXml, ApplicationPath = processExecutablePath, ProcessName = processName }; new CSVHelper().WriteRecord(t1); #endregion //Console.WriteLine("RawXPath is : " + preparedXml); }); resolveData.Wait(); //Task t = Task.Run(() => Program.c.SendMessage((m.X + "|" + m.Y))); Form1.textBox.Text = labelText + Environment.NewLine + "Elapsed time in Resolving data is message is :" + s1.ElapsedMilliseconds; #endregion }