Answer a question

I've created a swing application that will essentially use selenium to monitor field values displayed on a website and log their results to a file. The reason I'm using a swing GUI is to allow users to easily input the fields they wish to monitor by adding it to a JList.

Everything is working fine but when I click the button "Start Monitoring" (which creates a selenium thread and runs it), the selenium thread completely takes over and does not allow any interaction with the swing GUI.

I would like a button on the swing GUI "Stop Monitoring" to stop selenium, but this isn't possible since because I can't interact with the swing GUI while selenium is running.

Thanks in Advance

Answers

Your selenium code is locking the EDT or the Event Dispatch Thread, Swing's main thread for user interaction and GUI painting. The solution is to call the selenium code in a background thread such as by using a SwingWorker object. You can read more on how to do this at the SwingWorker tutorial: Concurrency in Swing

Once you get this fixed, you should be able to get your "stop monitoring" JButton to work.

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐