简体   繁体   中英

How to identify java swing button in a GUI application and click on that button using another Java code in eclipse?

I'm trying to create a small application to do some automation. I have a compiled and working GUI swing application that has a few buttons. I want to write another application in java using eclipse to do some automation on that GUI so my second application will click on the GUI buttons in specific order for example:

scenario 1:

  • click on button 2
  • then button number 5
  • then button number 1

scenario 2:

  • click on buttons number 3
  • then button number 2
  • then button number 4

The button locations are dynamic so moving the mouse to exact coordinates will not work.

I need to do something like UFT but very simple and using java in eclipse.

Note: I don't want to use any already existing libraries or applications.

You could use a Hashmap . The key would be the text (or however you uniquely identify the button) of the button and the value would be the button.

scenario 1: click on button 2 then button number 5 then button number 1

  1. Use the get() method of the Hashmap to get the button with text "2".
  2. Invoke doClick() on the button.
  3. repeat 1 and 2 for the other buttons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM