import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.File;
import login.Login;
import autoitx4java.AutoItX;
import com.jacob.com.LibraryLoader;
class LoginChildB extends Login{
}
public class SeleniumDesktopAppTest {
public static void main(String[] args) throws InterruptedException,AWTException {
final String[] argsCopy = args;
String jacobDllVersionToUse;
if (jvmBitVersion().contains("32")){
jacobDllVersionToUse = "jacob-1.18-x86.dll";
}
else {
jacobDllVersionToUse = "jacob-1.18-x64.dll";
}
Thread workerThread = new Thread(){
public void run(){
LoginChildB.main(argsCopy);
}
};workerThread.start();
File file = new File("lib", jacobDllVersionToUse);
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
AutoItX x = new AutoItX();
if(x.winWaitActive("JavaFX Welcome")){
Thread.sleep(1000*1);
x.send("partha"+"\t");
Thread.sleep(1000*1);
x.send("sarathi"+"\t");
Thread.sleep(1000*1);
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);
}
}
/**
*
* Returns if the JVM is 32 or 64 bit version
*/
public
static String jvmBitVersion(){
return System.getProperty("sun.arch.data.model");
}
}
在上面的代码中,我试图打开一个JavaFX表单(通过外部jar导入),并在按下提交按钮后输入文本字段。当我在Java 7中运行此代码时,我没有任何问题。但是当我使用Java 8运行此代码时,提交按钮没有被按下。似乎java.awt.Robot与Java 8不兼容。任何人都可以告诉我们如何解决这个问题?