private void GlobalHook_MouseEvent(object sender, MouseCoordinateEventArgs e) { //mouse down has occured //invoke UIA try { System.Windows.Automation.AutomationElement element = System.Windows.Automation.AutomationElement.FromPoint(e.MouseCoordinates); System.Windows.Automation.AutomationElement.AutomationElementInformation elementProperties = element.Current; //get properties from class via reflection System.Reflection.PropertyInfo[] properties = typeof(System.Windows.Automation.AutomationElement.AutomationElementInformation).GetProperties(); Array.Sort(properties, (x, y) => String.Compare(x.Name, y.Name)); //loop through each property and get value from the element foreach (System.Reflection.PropertyInfo property in properties) { try { var propName = property.Name; var propValue = property.GetValue(elementProperties, null); //if property is a basic type then display if ((propValue is string) || (propValue is bool) || (propValue is int) || (propValue is double)) { searchParameters.Rows.Add(false, propName, propValue); } } catch (Exception ex) { MessageBox.Show("Error Iterating over properties in window: " + ex.ToString()); } } } catch (Exception ex) { MessageBox.Show("Error in recording, please try again! " + ex.ToString()); } this.WindowState = FormWindowState.Normal; this.Close(); }
/// <summary> /// To find TreeGridStackedHeaderCell. /// </summary> public override void Find() { //create UITestControl from current instance UITestControl control = new UITestControl(); control.CopyFrom(this); //get the search properties from grid cell instance var properties = control.SearchProperties.ToList(); var headerCellProperties = new List <string>(); headerCellProperties.Add("ColumnName"); bool isContainProperty = false; foreach (var property in properties) { if (headerCellProperties.Contains(property.PropertyName)) { isContainProperty = true; break; } } if (isContainProperty) { // throw exception if properties are not enough to search a control if (properties.Count < 1 || properties.Where(p => p.PropertyName == "ColumnName").Count() < 1) { throw new UITestException("Not Enough Properties to find a control"); } // get the collection of child elements from SfTreeGrid container UITestControlCollection rowCollection = control.Container.GetChildren(); //bool flag = false; foreach (UITestControl row in rowCollection) { if (row.ClassName == "Uia.TreeGridHeaderRowControl") { UITestControlCollection collection = row.GetChildren(); foreach (UITestControl child in collection) { // check child is treegrid stackedHeaderCell if (child.ClassName == "Uia.TreeGridStackedHeaderCell") { Dictionary <string, string> childPropertiesDictonary = new Dictionary <string, string>(); System.Windows.Automation.AutomationElement automationElement = child.NativeElement as System.Windows.Automation.AutomationElement; if (automationElement == null) { continue; } System.Windows.Automation.AutomationElement.AutomationElementInformation current2 = automationElement.Current; string[] array = current2.ItemStatus.Split(new string[] { "#" }, StringSplitOptions.None); // assign the properties values to corresponding variable for condition checking childPropertiesDictonary.Add("ColumnName", array[0]); // set flag to true if all property values are match to child control foreach (var item in properties) { if (childPropertiesDictonary.Keys.Contains(item.PropertyName)) { if (childPropertiesDictonary[item.PropertyName] == item.PropertyValue) { isFound = true; } else { isFound = false; break; } } } // here this condition check is used for finding exact gridcell from its given proerty values if (isFound) { //set the corresponding cell values to its properties. this.columnName = array[0]; // copy the found cell as this instance this.CopyFrom(child); childPropertiesDictonary = null; break; } } } if (isFound) { break; } } } if (!isFound) { throw new UITestException("Not Maching control for this sepecific property"); } } else { base.Find(); System.Windows.Automation.AutomationElement automationElement = this.NativeElement as System.Windows.Automation.AutomationElement; if (automationElement == null) { throw new UITestException("Not Maching control for this sepecific property"); } System.Windows.Automation.AutomationElement.AutomationElementInformation current2 = automationElement.Current; string[] array = current2.ItemStatus.Split(new string[] { "#" }, StringSplitOptions.None); if (array.Count() != 0) { this.columnName = array[0]; } else { throw new UITestException("Not Maching control for this sepecific property"); } } }
private void GlobalHook_MouseEvent(object sender, MouseCoordinateEventArgs e) { //mouse down has occured //invoke UIA try { System.Windows.Automation.AutomationElement element = System.Windows.Automation.AutomationElement.FromPoint(e.MouseCoordinates); System.Windows.Automation.AutomationElement.AutomationElementInformation elementProperties = element.Current; LastItemClicked = $"[Name:{element.Current.Name}].[ID:{element.Current.AutomationId.ToString()}].[Class:{element.Current.ClassName}]"; lblSubHeader.Text = LastItemClicked; searchParameters.Rows.Clear(); //get properties from class via reflection System.Reflection.PropertyInfo[] properties = typeof(System.Windows.Automation.AutomationElement.AutomationElementInformation).GetProperties(); Array.Sort(properties, (x, y) => String.Compare(x.Name, y.Name)); //loop through each property and get value from the element foreach (System.Reflection.PropertyInfo property in properties) { try { var propName = property.Name; var propValue = property.GetValue(elementProperties, null); //if property is a basic type then display if ((propValue is string) || (propValue is bool) || (propValue is int) || (propValue is double)) { searchParameters.Rows.Add(false, propName, propValue); } } catch (Exception ex) { MessageBox.Show("Error Iterating over properties in window: " + ex.ToString()); } } } catch (Exception) { lblDescription.Text = "Error cloning element. Please Try Again."; //MessageBox.Show("Error in recording, please try again! " + ex.ToString()); } if (chkStopOnClick.Checked) { this.Close(); } }