I am writing a program that needs to open a list of URLs. I have firefox on Ubuntu12.04, and every time I kill firefox and reopen it, there will be a message asking if I want to restore the previous sessions or not, which is quite annoying.
I invoke firefox(in Java) using
Runtime r= Runtime.getRuntime();
r.exec("firefox -new-instance www.google.com");
and kill it using
r.exec("killall firefox");
Is there a way to kill and reopen firefox more gracefully? I want the program run automatically without any pop-up messages or human intervention. Thanks a lot!
Instead of launching firefox directly, launch a shell script that launches firefox in the background, then prints the PID of the firefox process on the standard out.
Then you can read the PID back through the
Process
object returned byRuntime.exec()
I think you cannot kill Firefox gracefully from Java, but you can change your firefox settings so that it wont ask you everytime it re-opens.
See the link Firefox Restore Options which will help you.
Use WebDriver to load and stop Firefox. You can get a separate Firefox instance with a separate profile. You won't be asked to restore sessions.
Then to close the browser and any child windows: