Name 속성과 ControlType 속성을 검색 할 때 Internet Explorer에서 TreeScope가 요소를 찾는 데 문제가 있습니다.TreeScope에서 FindFirst가 자동으로 요소를 찾지 못합니다.
mainElement는 "인터넷 Explorer_Server를 나타내는 AutomationElement를합니다.
모든 자동화 요소
이 UISpy에 mainElement 아래에 나열됩니다.공공 Auto.AutomationElement GetElementByNameAndControlType (Auto.AutomationElement mainElement, System.Windows.Automation.ControlType controlType 문자열 propertyName 형식)
{
Auto.AutomationElement target = null;
Auto.PropertyCondition typeCondition1 = new Auto.PropertyCondition (Auto.AutomationElement.ControlTypeProperty, controlType);
Auto.PropertyCondition typeCondition2 = new Auto.PropertyCondition(Auto.AutomationElement.NameProperty, propertyName);
Auto.AndCondition andCondition2 = new Auto.AndCondition(typeCondition1, typeCondition2);
target = mainElement.FindFirst(Auto.TreeScope.Descendants, andCondition2);
return target;
}
마침내 아래 코드로 요소를 찾을 수 있었지만 위의 코드가 작동하지 않는 이유를 실제로 이해하고자합니다.
공공 Auto.AutomationElement GetElementByIsValuePatternAvailablePropertyAndName (Auto.AutomationElement mainElement, 문자열 이름, Auto.ControlType controlType)
{
Auto.AutomationElement target = null;
Auto.Condition conditions = new Auto.AndCondition(new Auto.PropertyCondition(Auto.AutomationElement.IsEnabledProperty, true),
new Auto.PropertyCondition(Auto.AutomationElement.IsValuePatternAvailableProperty, true));
// Find all children that match the specified conditions.
Auto.AutomationElementCollection elementCollection = mainElement.FindAll (Auto.TreeScope.Descendants, conditions);
foreach (Auto.AutomationElement ae in elementCollection)
{
if (ae.Current.Name == name)
{
target = ae;
break;
}
}
return target;
}