mmarquee / ui-automation

Java wrapper for ms-uiautomation
https://mmarquee.github.io/ui-automation/
Apache License 2.0
111 stars 54 forks source link

UiAutomation getElementFromPoint doesn't work properly #21

Open RNowak4 opened 7 years ago

RNowak4 commented 7 years ago

It always returns root element - "Desktop".

The issue also occurs in demo project.

sameer1sharma commented 6 years ago

I was trying to use the code of version 0.5.0. I am getting only the Desktop. As explained by RNowak4. Please help me on this. RNowak4:- Could you get the solution for it?

mmarquee commented 6 years ago

As far as I can see, the commit added by RNowak4 fixed the issue. Do you have a code example, or are you using the example in the code?

sameer1sharma commented 6 years ago

Thanks mmarquee for the quick response ,

What I have done so far: • Slightly modified the DemoTreeWalker.java o Modified the Constructor to accept two integers as x and y coordinates of the current mouse position and create a point o In addition to finding the root element (using getRootElement() , I am testing two other methods: getFocusedElement() and getElementFromPoint() o Lets leave walk() and visit() out of the discussion. They are working fine.

Code: . . public MyDemoTreeWalker(int x, int y) {

          currentCursorPos = new POINT();
          this.currentCursorPos.x = x;
          this.currentCursorPos.y = y;

}

. . . public void run() { . . . AutomationElement root = automation.getRootElement(); AutomationElement focusedElement = automation.getFocusedElement(); AutomationElement clickedElement = automation.getElementFromPoint(currentCursorPos);

         System.out.println("Point: [" + currentCursorPos.x + "," + currentCursorPos.y + "]\n" +
                             "Root: " + root.getName() + " | " + root.getClassName() + "\n" +
                             "focusedElement: " + focusedElement.getName() + " | " + focusedElement.getClassName() + "\n" +
                             "clickedElement: " + clickedElement.getName() + " | " + clickedElement.getClassName() + "\n"
                                 );

. . . }

The above code gives the following output when I click in the To field in Outlook > New Email: Point: [383,214] Root: Desktop 1 | #32769 focusedElement: To | RichEdit20WPT clickedElement: Desktop 1 | #32769

Problem: No matter what is the value of currentCursorPos, clickedElement always returns Desktop 1 Let me know if I have missed anything.

Few additional observations: • I am using 0.5 version (Master) but I am not able to find the fix provided by RNowak4  • However, I can see here you have merged this and other changes with master.  To add: The link says build for #21 failed. Could you have reverted the changes? It is very likely that code has gone through several changes and refactoring, hence things have moved. So, please ignore the above observations, if not relevant. 

Nethaji-pandiarajan commented 2 years ago

This issue is not solved yet..Please try to resolve this error

linxu commented 5 months ago

I also encountered the same problem, can you fix it?