【问题标题】:I can't disable with setEnabled(false), the button is not disabled in correct phase我不能用 setEnabled(false) 禁用,按钮在正确的阶段没有被禁用
【发布时间】:2015-07-31 12:42:52
【问题描述】:

我有 Selenium WebDriver callSe.test(); + JFrame。 下面是frame的构造函数:

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();
}

所以我希望在btnRun.setEnabled(false); 之后按钮被禁用,但不是。它只是被标记并且框架只是有点冻结。 仅当整个构造函数完成时,该按钮才变为不可点击(假,禁用)。 为什么会这样?我想,当我按下要禁用的按钮时,我将启用。也许我必须在 PleaseWait 中使用模态对话框?

【问题讨论】:

    标签: selenium jframe webdriver


    【解决方案1】:

    在单独的线程中运行 Selenium 任务。

       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();
    
        }
    });
    

    【讨论】:

    • 您好,谢谢!这有效:) 但我现在有新问题,在过程完成后,框架不可编辑。此外,当我在 Class CheckBuildVersion 中设置时:textPaneCurrentBuild.setText("Test"); 文本不会在此字段中设置。当我使用线程时,textPaneCurrentBuild.setText(callSe.getBuild()); 也不起作用。
    • 通过在这些行上放置一个断点来调试它,看看它是否在那里。还尝试在线程调用之前和之后设置值
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    • 1970-01-01
    • 2015-06-21
    • 1970-01-01
    相关资源
    最近更新 更多