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

Running on older Windows versions (7, 8 & 8.1) (was: how to run this in win64)

Open CyrilFeng opened this issue 6 years ago • 62 comments

CyrilFeng avatar Oct 10 '17 11:10 CyrilFeng

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

mmarquee avatar Oct 10 '17 12:10 mmarquee

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

CyrilFeng avatar Oct 11 '17 01:10 CyrilFeng

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.

mmarquee avatar Oct 11 '17 11:10 mmarquee

I saw the Notepad window

CyrilFeng avatar Oct 11 '17 12:10 CyrilFeng

WinNT.HRESULT result0 = uRoot.QueryInterface(new Guid.REFIID(IUIAutomationElement3.IID), pRoot); this function return -2147467262

CyrilFeng avatar Oct 14 '17 06:10 CyrilFeng

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.

mmarquee avatar Oct 14 '17 07:10 mmarquee

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.

mmarquee avatar Oct 14 '17 08:10 mmarquee

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.

mmarquee avatar Oct 14 '17 08:10 mmarquee

it return "Not found, retrying"

CyrilFeng avatar Oct 14 '17 09:10 CyrilFeng

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.

mmarquee avatar Oct 14 '17 11:10 mmarquee

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).

parvuselephantus avatar Oct 15 '17 12:10 parvuselephantus

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.

mmarquee avatar Oct 15 '17 17:10 mmarquee

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.

mmarquee avatar Oct 16 '17 08:10 mmarquee

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)

parvuselephantus avatar Oct 16 '17 17:10 parvuselephantus

Are you using Wndows 7 as above?

mmarquee avatar Oct 16 '17 18:10 mmarquee

Yes, I am. It's installed as guest OS in VirtualBox.

parvuselephantus avatar Oct 16 '17 18:10 parvuselephantus

Hmm. That should work, I will try on a Windows 7 machine tomorrow.

mmarquee avatar Oct 16 '17 19:10 mmarquee

hi, does the legacy version support both IUIAutomation and IUIAutomation3? it will be grate, because i need it both for windows7 and windows10

igivon avatar Oct 18 '17 12:10 igivon

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

mmarquee avatar Oct 18 '17 18:10 mmarquee

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

igivon avatar Oct 19 '17 05:10 igivon

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 ;-)

mmarquee avatar Oct 19 '17 06:10 mmarquee

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);
}

igivon avatar Oct 22 '17 06:10 igivon

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)

mmarquee avatar Oct 22 '17 16:10 mmarquee

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 avatar Oct 22 '17 16:10 parvuselephantus

@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.

mmarquee avatar Oct 22 '17 16:10 mmarquee

(also see update above)

mmarquee avatar Oct 22 '17 16:10 mmarquee

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 avatar Oct 22 '17 19:10 parvuselephantus

@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.

mmarquee avatar Oct 22 '17 19:10 mmarquee

@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.

mmarquee avatar Oct 24 '17 11:10 mmarquee

The issue is in getRootElement from the automation library call itself.

Not sure why that would fail on Windows 7.

mmarquee avatar Oct 24 '17 11:10 mmarquee