2017-01-04 7 views
1

왜 UIAutomation이 크롬의 상황에 맞는 메뉴 요소를 가져올 수 없습니까?Microsoft ui-automation이 크롬의 상황에 맞는 메뉴 요소를 가져올 수 없습니다.

C# 코드 : 아래 코드는 루트 요소에 가입합니다.

public void SubscribeToInvoke() 
     { 
      Automation.AddAutomationEventHandler(AutomationElement.MenuOpenedEvent, 
        AutomationElement.RootElement, 
        TreeScope.Descendants, UIAEventHandler); 

      Automation.AddAutomationEventHandler(AutomationElement.MenuClosedEvent, 
        AutomationElement.RootElement, 
        TreeScope.Descendants, UIAEventHandler); 
     } 

벨로우즈 이벤트

구글 크롬의 경우 해고되지 않지만, 다른 경우 (즉, IE 나 파이어 폭스 나 다른 응용 프로그램)에 괜찮습니다.

 private void UIAEventHandler(object sender, AutomationEventArgs e) 
     { 
      AutomationElement sourceElement; 
      sourceElement = sender as AutomationElement; 
      if (e.EventId == AutomationElement.MenuOpenedEvent) 
      { 
      } 
      else if (e.EventId == AutomationElement.MenuClosedEvent) 
      { 
      } 
     } 

코드 변경이 필요하거나이 문제에 대한 대안이 있습니까?

답변

2

FromPoint()라는 메서드를 사용하여이 작업을 수행했습니다. 내 유스 케이스는 오른쪽 클릭하여 붙여 넣기 이벤트를 얻는 것이 었습니다.

1 단계 : 메뉴 열고 닫는 이벤트를 구독 :

public void SubscribeToInvoke() 
     { 
      Automation.AddAutomationEventHandler(AutomationElement.MenuOpenedEvent, 
        AutomationElement.RootElement, 
        TreeScope.Descendants, UIAEventHandler); 

Automation.AddAutomationEventHandler(AutomationElement.MenuClosedEvent, 
        AutomationElement.RootElement, 
        TreeScope.Descendants, UIAEventHandler); 
     } 

2 단계 : 마우스 및 MenuCloseEvent의 혁지 타이머의 현재 위치를 얻을 것이다 타이머를 시작 MenuOpenedEvent합니다.

if (e.EventId == AutomationElement.MenuOpenedEvent) 
      { 
       timer_Chrome.Enabled = true; 
      } 
      else if (e.EventId == AutomationElement.MenuClosedEvent) 
      { 
       timer_Chrome.Enabled = false; 
      } 

3 단계 : 마우스 위치에있는 요소를 가져

  System.Windows.Point point = new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y); 
      AutomationElement sourceElement = AutomationElement.FromPoint(point);