2013-08-10 23 views
5

.NET UIオートメーションを使用しようとしています。 私が知っているサードパーティのアプリケーションは.NETで書かれていますが、ソースコードはありません。 私はアプリケーションを起動しています。 Process.Start( "exe path"); とPROCESSID を取得し、その後UIオートメーションとメニュー項目

this.MainWindow = AutomationElement.RootElement.FindFirst 
        (TreeScope.Children, 
        new AndCondition(
         new PropertyCondition(AutomationElement.ProcessIdProperty, this.ProcessId), 
         new PropertyCondition(AutomationElement.NameProperty, InitialWindowName) 
         )); 

これは を見つける作業しかし、メインウィンドウには、一般的な「ファイルを持っているメニューバーがありますされることにより、メインアプリケーションウィンドウの検索、編集、... 「だから

は、次のステップIは、メニューバーを選択しているので

var menuBar = this.MainWindow.FindFirst(TreeScope.Children, 
             new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "menu bar")); 
       var fileMenu = menuBar.FindAll(TreeScope.Children, Condition.TrueCondition)[0]; 
       var expandPattern = fileMenu.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; 
       if (expandPattern.Current.ExpandCollapseState != ExpandCollapseState.Expanded) 
        expandPattern.Expand(); 
       Thread.Sleep(3000); 

で、ファイルメニューを展開し、 『ファイル』メニューオプションは、メニューバーの最初のオプションであるため、これが拡大している」ファイルをメニューオプション

ここで、「ファイル」メニューリストの印刷メニュー項目を呼び出したいとします。

印刷メニュー項目は名前を持つ "印刷ドキュメントのCtrl + P"

ので、私は

var printMenuItem = this.MainWindow.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty,"Print Document Ctrl+P")); 

ためしかし、成功せずに検索します。 私はこの

var list = this.MainWindow.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty,"menu item")); 
for (int i = 0; i < list.count; i++) 
{ 
    if (list[0].Current.Name.IndexOf("Print") > -1)... 

答えて

2

のように私はこれを試してみましたが、印刷メニュー

を見つけることができた、すべての項目の子孫を取得し、彼らは成功せず、その中に「印刷」を持っている場合を見つけるために名前をループのように、別の方法を試してみました
var printMenu = fileMenu.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Print")); 
+0

ありがとうございました。それは働いた –

関連する問題