我有Selenium WebDriver Abs
+ JFrame。
这是框架的构造函数:
callSe.test();
所以我希望在public AutoFrame() {
textFieldVersion.setColumns(10);
textFieldUrl.setColumns(10);
textPaneIsBuildCorrect.setBackground(UIManager.getColor("menu"));
btnRun.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
btnRun.setEnabled(false);
getEnteredVer();
CheckBuildVersion callSe = new CheckBuildVersion();
callSe.test();
textPaneIsBuildCorrect.setText(callSe.getIsBuildCorrect());
if (textPaneIsBuildCorrect.getText().contains("The Build is correct!")) {
textPaneIsBuildCorrect.setForeground(Color.blue);
}
else {
textPaneIsBuildCorrect.setForeground(Color.red);
}
textPaneCurrentBuild.setText(callSe.getBuild());
}
});
initGUI();
}
之后禁用该按钮,但不是。它只是标记,框架只是冻结。
只有当整个构造函数完成时,该按钮才会变为不可点击(假,禁用)。
为什么会这样?我想,当我按下按钮被禁用时,我将启用。也许我必须使用PleaseWait的模态对话框?
答案 0 :(得分:1)
在单独的线程中运行Selenium Task。
Thread thread = new Thread() {
public void run() {
//your selenium actions
}
};
thread.start();
对于你的情况
btnRun.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
btnRun.setEnabled(false);
getEnteredVer();
Thread thread = new Thread() {
public void run() {
CheckBuildVersion callSe = new CheckBuildVersion();
callSe.test();
textPaneIsBuildCorrect.setText(callSe.getIsBuildCorrect());
if (textPaneIsBuildCorrect.getText().contains("The Build is correct!")) {
textPaneIsBuildCorrect.setForeground(Color.blue);
}
else {
textPaneIsBuildCorrect.setForeground(Color.red);
}
textPaneCurrentBuild.setText(callSe.getBuild());
}
};
thread.start();
}
});