ui-automation icon indicating copy to clipboard operation
ui-automation copied to clipboard

getDocument(0) throws IndexOutOfBoundsException

Open krasnyd opened this issue 5 years ago • 3 comments

I have this code:

UIAutomation automation = UIAutomation.getInstance();
AutomationWindow window = automation.getDesktopWindow("ZAV - 1.0.05");
AutomationDocument ad = window.getDocument(0);
System.out.println(ad.getText());

But it throws this exception:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:657)
	at java.util.ArrayList.get(ArrayList.java:433)
	at mmarquee.automation.controls.AutomationContainer.getElementByControlType(AutomationContainer.java:110)
	at mmarquee.automation.controls.AutomationContainer.getDocument(AutomationContainer.java:768)
	at cz.krasnyd.writer.Test.main(Test.java:20)

When I look to inspect.exe (screenshot below), I see there some Document elements and I want get their value. Other functionalies works well (e.g. function getButton) and for example this code:

List<AutomationBase> a = window.getChildren(true);
for(AutomationBase ab : a){
   if(ab.getClassName().equals("WindowsForms10.RichEdit20W.app.0.2004eee")) {
      ...
   }
}

...returns me some Document elements, but I cannot get their value. Don't you know where the problem might be or do I use the library wrong?

*some things are in my local language ("vlastní" = "Custom", "podokno" = "Pane", "skupina" = "Group") inspect

krasnyd avatar Jan 25 '19 19:01 krasnyd

Hi, I think you'll have to follow the hierarchy down, getting each level. Not sure that we have a 'Group' control though. Is this a publicly available program so I can look at it and see whether I can get the control you want? Mark

mmarquee avatar Jan 27 '19 15:01 mmarquee

Hi Mark. I sent it to your email.

krasnyd avatar Jan 28 '19 18:01 krasnyd

I am really sorry, but I seem to be locked out of the email address and Microsoft won't unlock it. I have changed the email address to my personal one, so if you can resend it that would be super. If not, I'll understand

mmarquee avatar Jan 31 '19 08:01 mmarquee