Sikuli:java.lang.IllegalThreadStateException:无法从事件调度程序线程调用方法
当我尝试使用java web驱动程序和sikuli使用flex自动化一个网站应用程序时,在使用以下代码单击按钮后,我得到错误“java.lang.IllegalThreadStateException:无法从事件调度程序线程调用方法”Sikuli:java.lang.IllegalThreadStateException:无法从事件调度程序线程调用方法,java,multithreading,selenium,webdriver,sikuli,Java,Multithreading,Selenium,Webdriver,Sikuli,当我尝试使用java web驱动程序和sikuli使用flex自动化一个网站应用程序时,在使用以下代码单击按钮后,我得到错误“java.lang.IllegalThreadStateException:无法从事件调度程序线程调用方法” public static void clickImage(String folder, String file) throws FindFailed { Screen screen; File loc = new File("i
public static void clickImage(String folder, String file) throws FindFailed {
Screen screen;
File loc = new File("images/" + folder + "/" + file + ".png");
Pattern image = new Pattern(loc.getAbsolutePath());
screen = new Screen();
if (isImagePresent(image, 20)) {
try{
waitUntilLoadCompletes(folder);
screen.click(image,0);//This method is throwing error
}catch(Exception e){System.out.println("click has some prblm"+e);}
} else {
new Exception(file+"not found");
}
此外,我还得到了以下错误
[错误]鼠标向下:按钮仍被按下-使用所有
看起来它单击了图像,但没有释放按钮,这意味着它按下了鼠标按钮,但没有释放。在释放按钮之前,我想它会抛出错误
我在下面的fn中使用sleep,这在上面的代码中使用
public static boolean isImagePresent( Pattern img, int time) {
Screen screen=new Screen();
int i = 0;
while (i < time) {
try {
System.out.println(screen.exists(img).toString());
return true;
} catch (Exception e) {
System.out.println("waiting for image--- "+i+" seconds");
}
i++;
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(Library.class.getName()).log(Level.SEVERE, null, ex);
}
}
return false;
}
publicstaticbooleanimagepresent(模式img,int-time){
屏幕=新屏幕();
int i=0;
while(我<时间){
试一试{
System.out.println(screen.exists(img.toString());
返回true;
}捕获(例外e){
System.out.println(“等待映像--”+i+“秒”);
}
i++;
试一试{
睡眠(1000);
}捕获(中断异常例外){
Logger.getLogger(Library.class.getName()).log(Level.SEVERE,null,ex);
}
}
返回false;
}
Wee不应该从由于某些事件而执行的方法内部调用该方法/类。在我的例子中,我是从Buttonactionperformed方法调用构造函数的
我使用了一个变量,创建了单独的线程,并调用了构造函数。现在可以工作了
@Override
public void run() {
while(true){//System.out.println(start);
if(start){jButton1.setEnabled(false);
new Driver(login, jComboBox2.getSelectedItem().toString());
jButton1.setEnabled(true);
start=false;
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(LoginFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
}