2013-08-10 11 views
5

मैं .NET UI स्वचालन का उपयोग करने की कोशिश कर रहा हूं। मेरे पास एक तृतीय पक्ष एप्लिकेशन है जो मुझे पता है .NET में लिखा गया है, लेकिन मेरे पास कोई स्रोत कोड नहीं है। मैं प्रक्रिया के साथ एप्लिकेशन शुरू कर रहा हूं। स्टार्ट ("exe path"); और processID हो रही है और तब तकयूआई स्वचालन और मेनू आइटम

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

इस को खोजने के काम कर रहा है लेकिन मुख्य विंडो में, वहाँ आम "फाइल है कि एक मेनू पट्टी है मुख्य आवेदन खिड़की के लिए खोज, संपादित करें, ... "

तो, अगले कदम के लिए मैं मेनू पट्टी का चयन करें और

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

धन्यवाद। वह काम किया –

संबंधित मुद्दे