.NET UI 자동화를 사용하려고합니다. .NET에서 작성된 타사 응용 프로그램이 있지만 소스 코드가 없습니다. 나는 응용 프로그램을 시작하고있다. Process.Start ("exe path"); 및 프로세스 ID 을 받고 다음UI 자동화 및 메뉴 항목
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);
으로 파일 메뉴를 확장하여"파일 "메뉴 옵션은 메뉴 바에서 첫 번째 옵션은, 그래서 이것은 확대"파일을 "메뉴 옵션
이제 "파일"메뉴 목록에서 인쇄 메뉴 항목을 호출하고 싶습니다.
인쇄 메뉴 항목은 그래서
var printMenuItem = this.MainWindow.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty,"Print Document Ctrl+P"));
위한 그러나 성공하지 검색
이름 "문서 인쇄 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)...
감사합니다. 그게 효과가있어. –