开发者

Controlling selenium through a Swing GUI

开发者 https://www.devze.com 2023-02-08 08:07 出处:网络
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

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 ru开发者_JAVA百科nning.

Thanks in Advance


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号