简体   繁体   English

如何在GUI应用程序中识别Java摆动按钮并使用Eclipse中的另一个Java代码单击该按钮?

[英]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. 我有一个经过编译且可以使用的GUI Swing应用程序,该应用程序具有几个按钮。 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: 我想使用eclipse在Java中编写另一个应用程序以对该GUI进行一些自动化,因此我的第二个应用程序将按特定顺序单击GUI按钮,例如:

scenario 1: 方案1:

  • click on button 2 点击按钮2
  • then button number 5 然后按数字5
  • then button number 1 然后是按钮编号1

scenario 2: 方案2:

  • click on buttons number 3 点击数字3
  • then button number 2 然后是数字2
  • then button number 4 然后是按钮编号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. 我需要做类似UFT的操作,但是非常简单,并且需要在eclipse中使用java。

Note: I don't want to use any already existing libraries or applications. 注意:我不想使用任何已经存在的库或应用程序。

You could use a Hashmap . 您可以使用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:单击按钮2,然后单击数字5,然后单击数字1

  1. Use the get() method of the Hashmap to get the button with text "2". 使用Hashmap的get()方法获取带有文本“ 2”的按钮。
  2. Invoke doClick() on the button. 在按钮上调用doClick()。
  3. repeat 1 and 2 for the other buttons. 对其他按钮重复1和2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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