java_enthu
java_enthu

Reputation: 2327

Not able to click the button on File Download with JWinAuto

I am new to JWinAuto and AutoIT. I want to click the save button on the File Download control. I am able to get the focus on the button but it doesn't click if the current File Download is not in focus. I have set it to top and activated it to have it focused. But still I am not able to click the button. I am attaching the code here. Can any one please tell if I am missing something..

            private static final WString BLANK_STRING = new WString("");
            private static final WString FILE_DOWNLOAD = new WString("File Download");
            System.out.println("hi..");
            JAutoITx wrapper = JAutoITx.INSTANCE;
            wrapper.AU3_Init();
            wrapper.AU3_WinWait(FILE_DOWNLOAD, BLANK_STRING, 15);
            wrapper.AU3_WinActivate(FILE_DOWNLOAD, BLANK_STRING);
            System.out.println(wrapper.AU3_WinActive(FILE_DOWNLOAD, BLANK_STRING));
            wrapper.AU3_WinSetOnTop(FILE_DOWNLOAD, BLANK_STRING, 0);
            wrapper.AU3_ControlFocus(FILE_DOWNLOAD, BLANK_STRING, new WString(
                            "[CLASS:Button; INSTANCE:2]"));
            wrapper.AU3_ControlClick(FILE_DOWNLOAD, BLANK_STRING, new WString(
                            "[CLASS:Button; INSTANCE:2]"), BLANK_STRING, 1, 6660, 500);
            wrapper.AU3_Send(new WString("s"), 0);

Upvotes: 2

Views: 645

Answers (1)

Jos van Egmond
Jos van Egmond

Reputation: 2360

You don't have to focus the window for the ControlClick to work. Neither does it have to be activated, set on top, etc. I understand those are just tests but the ControlClick line should be enough on its own.

This line:

 wrapper.AU3_ControlClick(FILE_DOWNLOAD, BLANK_STRING, new WString("[CLASS:Button; INSTANCE:2]"), BLANK_STRING, 1, 6660, 500);

ControlClick "title", "text", "controlID" [, button [, clicks [, x [, y ]]]]

You're basically saying: Click on the button 6660 pixels from the left side of the button and 500 from the top side of the button. That button might receive the message and check if the client clicked inside its own coordinates. If it does that, the button will have to be 6660x500 pixels large and I'm guessing here but I'm pretty sure it is not that big.

Especially since the parameters are optional, why are you passing that at all? Just do something like this:

 wrapper.AU3_ControlClick(FILE_DOWNLOAD, BLANK_STRING, new WString("[CLASS:Button; INSTANCE:2]"), BLANK_STRING, 1, 0, 0);

See if it works with just the ControlClick. And as a side note, some applications do check if the window is active before they process any commands sent to the controls, but most applications do not.

If this doesn't answer your question, then I'd like to know which application the "File download" button belongs to so I can write a test myself.

Upvotes: 2

Related Questions