Why UIAutomation is not able to fetch chrome's context menu elements.
C# Code: The below code will subscribe to the root element.
public void SubscribeToInvoke()
{
Automation.AddAutomationEventHandler(AutomationElement.MenuOpenedEvent,
AutomationElement.RootElement,
TreeScope.Descendants, UIAEventHandler);
Automation.AddAutomationEventHandler(AutomationElement.MenuClosedEvent,
AutomationElement.RootElement,
TreeScope.Descendants, UIAEventHandler);
}
The bellow event is not getting fired in the case of google chrome, but in other cases (i.e. IE or Firefox or any other application) it is fine.
private void UIAEventHandler(object sender, AutomationEventArgs e)
{
AutomationElement sourceElement;
sourceElement = sender as AutomationElement;
if (e.EventId == AutomationElement.MenuOpenedEvent)
{
}
else if (e.EventId == AutomationElement.MenuClosedEvent)
{
}
}
Is there any code changes required or is there any alternative solution for this problem?
I have achieved this task by using a method called as FromPoint(). My use case was to get right click and paste event.
Step 1: Subscribe to the menu open and close event:
Step 2: When MenuOpenedEvent start timer which will get the current location of your mouse and on MenuCloseEvent strop timer.
Step 3: Get the element at the mouse location