1

NameプロパティとControlTypeプロパティを検索するときに、TreeScopeがInternetExplorerで要素を見つけるのに問題があります。

mainElementは、「internetExplorer_Server」を表すAutomationElementです。

すべての自動化要素は、UISpyのmainElementの下に一覧表示されます。

public Auto.AutomationElement GetElementByNameAndControlType(Auto.AutomationElement mainElement、System.Windows.Automation.ControlType controlType、string 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;
    }

私はついに以下のコードで要素を見つけることができましたが、上記のコードが機能しなかった理由を本当に理解したいと思います。

public Auto.AutomationElement GetElementByIsValuePatternAvailablePropertyAndName(Auto.AutomationElement mainElement、string name、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;

}

4

1 に答える 1