ui-automation
ui-automation copied to clipboard
Running on older Windows versions (7, 8 & 8.1) (was: how to run this in win64)
Hi, Do you mean with 64-bit WIndows, or 64-bit Java? I have it running with both these, do you get errors or failures? Start with running the demo examples that would show you what is happening and how to get basic information, both for the example test-bed programs and Explorer and Notepad Let me know how you get on
I try to run it with the follow code
UIAutomation automation = UIAutomation.getInstance();
AutomationApplication application = automation.launchOrAttach("notepad.exe");
application.waitForInputIdle(5000);
AutomationWindow window = automation.getDesktopWindow("Untitled - Notepad");
But when I run this it gives a Exception
Exception in thread "main" java.lang.NullPointerException
at mmarquee.automation.UIAutomation.get(UIAutomation.java:257)
at mmarquee.automation.UIAutomation.getDesktopWindow(UIAutomation.java:288)
at foolqq.Test.main(Test.java:18)
win8 64bit and jdk1.8 64bit
Do you see Notepad start? I don't have access to an Windows 8 machine, but it might be an issue with the version of the COM control in Windows 8.
I saw the Notepad window
WinNT.HRESULT result0 = uRoot.QueryInterface(new Guid.REFIID(IUIAutomationElement3.IID), pRoot); this function return -2147467262
Hi, thanks. This looks like it a Windows 8 issue - The IUIAutomationElement3 interface is only available in Windows 8.1 and above. I don't have access to a Windows 8 machine on which to test this. I will think about what needs to be done over this weekend, unless you feel like having a go at trying to fix it? I'll stick some notes here, as I think about it.
These are the minimums for the parts that we are using internally,
- IUIAutomationElement3 is available from Windows 8.1 onwards.
- IUIAutomation3 is available from Windows 8.1 onwards.
Update: I have created a branch called "windows8-legacy-support", which has an example implementation for a possible version that supports Windows 8, using the IUIAutomation2 and IUIAutomationElement2. If you run the MainLegacy demo, and let me know whether it works (I don't have machine on which to test it). If it is OK, I have some refactoring to do on it, as it has lots of copied code in, but it SHOULD work. I will also update documentation.
it return "Not found, retrying"
Well, it's a start. It is now loading the controls properly, and looking for the notepad application. Is you Windows installation non-English? It might not be able to find the name of the window if it is not 'Notepad'. It would be possible to add support for other languages here, but if the window title is non-English, then change the demo to try and find the window.
Meanwhile I will see if the Notepad example works with the Legacy version.
I have very same issue. My environment is Windows 7 64bit - English version. Java jdk1.8.0_05. Code:
UIAutomation automation = UIAutomation.getInstance();
automation.getDesktopWindow("Calculator");
Exception in thread "main"
java.lang.NullPointerException
at mmarquee.automation.UIAutomation.get(UIAutomation.java:257)
at mmarquee.automation.UIAutomation.getDesktopWindow(UIAutomation.java:303)
at ktm.MainPOC.main(MainPOC.java:13)
I do not have any Visual Studio installed (I try to take the biggest possible JNA advantage on clean windows + Java).
Hi, I think this is the same thing, but for Windows 7, it uses the even earlier version of the COM library. I will make the legacy version use the oldest available library and make sure it still works - it will go into the windows8-legacy-support branch if you can get the code out and build it yourself.
OK, I have merged all the elements to use the lowest version of the code by default, which as broken one thing, but that is only used in my demos, and I can probably work around it sooner or later.
Please check the windows8-legacy-support
branch to test it.
I have downloaded both your newest version and this:
https://github.com/mmarquee/ui-automation/tree/windows8-legacy-support
version as well. Both crash on my Calculator test with same exception:
Exception in thread "main" java.lang.NullPointerException at com.sun.jna.platform.win32.COM.COMInvoker._invokeNativeObject(COMInvoker.java:42) at com.sun.jna.platform.win32.COM.Unknown.QueryInterface(Unknown.java:70) at mmarquee.automation.UIAutomation.<init>(UIAutomation.java:58) at mmarquee.automation.UIAutomation.getInstance(UIAutomation.java:72) at ktm.MainPOC.main(MainPOC.java:12)
Are you using Wndows 7 as above?
Yes, I am. It's installed as guest OS in VirtualBox.
Hmm. That should work, I will try on a Windows 7 machine tomorrow.
hi, does the legacy version support both IUIAutomation and IUIAutomation3? it will be grate, because i need it both for windows7 and windows10
IUIAutomation is still supported on all platforms. There is one call to IUIAutomationElement3 - to show a popup men, but that should fail gracefully if called from Window 7 or 8
i know IUIAutomation is supported on all platforms but when trying to open Calculator or get any element it fails on Windows 7 64 that support only IUIAutomation. the only way i manage to get it work is to remove the usage of IUAutomation3 and change it to IUAutomation. also i didnt see the fall back to IUIAutomation from IUIAutomation3 or any mechanism that will deal with the different platforms . i will be glad if you can point me to it if its presents
Are you looking at the https://github.com/mmarquee/ui-automation/tree/windows8-legacy-support branch, as that is where the changes are? Like you said this has involved replacing all the IUIAutomationElement3 and IUIAutomation3 with their previous versions. This caused a problem with the showContextMenu that is only in IUIAutomationElement3, so there is a COM IUnknown query in there to check that the interface is supported, otherwise it will fail. If you give that branch a try (I don;t have regular access to a machine with Windows 7 or 8 on it), and see whether it work as you expect. If not Pull Requests are always welcome ;-)
i have tried the legacy branch but it still has issues and not working good with windows7 64. for example: getFocusedElement in the end, try to use the IUIAutomation3 when trying to getAutyomationElementFromRefrance and throws exception
public IUIAutomationElement getAutomationElementFromReference(final PointerByReference pbr) throws AutomationException { Unknown uElement = makeUnknown(pbr.getValue());
WinNT.HRESULT result0 = uElement.QueryInterface(new Guid.REFIID(IUIAutomationElement3.IID), pbr);
if (COMUtils.FAILED(result0)) {
throw new AutomationException(result0.intValue());
}
return IUIAutomationElementConverter.PointerToInterface(pbr);
}
Thanks, - OK, I've fixed that and committed again, so can you test again. UPDATE: I've just updated again and removed some more non-backward compatibility issues - most;y in the tests)
I just checked - still getting exactly the same NullPointerException (I took latest 'windows8-legacy-support' version). Any Idea what I could have done wrong? Is there anything I could check for you?
@parvuselephantus Is it the same stack trace as before? Code you send me the code that makes it happen? That way I can see whether there is anything obvious about that would make it not work, and it myself and debug it.
(also see update above)
Hi @mmarquee. Sorry for that, but I confirm it's all exactly same: same code, same win7 64bit, same stacktrace (even numbers of lines are same). I have just downloaded the newest version of ui-automation-windows8-legacy-support branch.
@parvuselephantus Oh no. I am not going to be near a Window 7 PC until tuesday (and even then might not be able to get to use it). I'll try and get access to it and see what happens.
@parvuselephantus I have just run this on a Windows 7 machine, and it fails (even when run from the legacy branch), so I have something to work through now. It should work, as the interface is implemented in Windows 7.
The issue is in getRootElement
from the automation library call itself.
Not sure why that would fail on Windows 7.