permaculture playing cards*
The moose likes I/O and Streams and the fly likes how to perform mouse click action using java. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "how to perform mouse click action using java." Watch "how to perform mouse click action using java." New topic
Author

how to perform mouse click action using java.

gow tham
Greenhorn

Joined: Sep 29, 2013
Posts: 29
Hi friends, I'm a unit tester. I want to access install shield using java code like clicking next button(mouse listener) type customized install location (using keyboard listener).I have googled regarding how to perform mouse click for particular button(most probably Next and Cancel button, radio, check box) but I didn't get any idea. please explain me in simple way how to click perticular(next,or cancel)button in install shield using java code. suggestions are highly appreciate. I want to use my own java code to achieve this without using httpunit, or any other framework (Junit,testng). please help me....!
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2176
    
  47
You are going to struggle to do this using Java. There maybe a solution, using the java.awt.Robot class, which allows you to move the mouse to a specific screen location and perform a mouse click but whether this will be passed through to another application or not I don't know. You may have to click twice, once to get focus and once to perform the button click. There is also the problem that you need to know the screen location of the button you want to press.

Personally I'd use an automated GUI testing tool rather than writing my own, there are open source versions available if you don't want to buy one.
gow tham
Greenhorn

Joined: Sep 29, 2013
Posts: 29
Hi Tony, Yep..I'm agree with you. I knew It's a big task to perform with java. I have struggling to innovate this task. My friend suggested me to post my queries in this site. It may help me to get different opinions, different ideas.

Anyhow thank you so much for yours valuable advise...(I'm gathering knowledge on robot java class that you have posted.)

Please help me experts to come out this problem....
J Coakley
Greenhorn

Joined: Oct 02, 2013
Posts: 1

This seems like a place you could use the JNI. Unfortuanantly, the downside of WORA is that
Java doesn't always offer complete control over operating system tasks, like moving the mouse,
clicking, etc. This is were calling native code with the JNI comes in, stuff like this can be done in C
easier than in Java.


Finally, a useful forum with nice people!
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2176
    
  47
J Coakley wrote:This is were calling native code with the JNI comes in, stuff like this can be done in C
easier than in Java.

Welcome to the ranch.

I agree you could write the code in a native language and interface to it via JNI. I suppose the big question is given the purpose of the app is just to click a button in another app why would you want to do this though via JNI rather just than write the whole program in the native language.

Unless the OP provides more information on what exactly the application is doing and why it has to be written in Java it's hard to give more definitive advice, other than don't do it in Java.
gow tham
Greenhorn

Joined: Sep 29, 2013
Posts: 29
thanks coakley, is it possible to integrate C in java using JNI framework?. Actually yours comment make me sense. if you give me some ideas or flow about the frame that would be more help full to me innovate my task. Regards, Santhosh.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2176
    
  47
You don't integrate C into Java, you write a C library which you call from Java using JNI. It is not a simple thing to do and it restricts the Java application to whatever platform(s) your native library will support.
gow tham
Greenhorn

Joined: Sep 29, 2013
Posts: 29
oh..thanks tony. is there any other way to achieve this? My objective is wanna perform mouse click() action which we normally do by manually.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2176
    
  47
san thosh wrote:oh..thanks tony. is there any other way to achieve this? My objective is wanna perform mouse click() action which we normally do by manually.

There isn't any other way I know of. Why does it have to be done in Java?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

If you're trying to automate the installation of software on Windows, then writing code which will automatically click the installer's buttons is not going to be a solution. That's been the approach of malware writers for a long time and nowadays Windows has security features which prevent that.

If you have a product which is being installed on hundreds of machines and you always click the same buttons, I'd suggest getting the writers of that product to provide you with a "silent" version of the installer which doesn't pester you to click on the buttons.
 
 
subject: how to perform mouse click action using java.
 
Similar Threads
tracing mouse button click (left-middle-right)
mouseclicked
major problem with html:cancel and html:submit
refer name in HTML for <input type="image"< failed
cancel button problem in struts1.1