Steven
Steven

Reputation: 33

Controlling selenium through a Swing GUI

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

Upvotes: 3

Views: 2057

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285403

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.

Upvotes: 4

Related Questions