How to remotely control Firefox from a script in OSX

I need to write some scripts that access some sites. A script from the command line will receive some pages, publish some forms, a screen fragment, some information, etc.

It cannot be a library "browser" like libwww-perl, because some steps may require user interaction (katches, forms only ajax, any unexpected interactions, etc.).

The most practical way I can think of is to remotely open a tab in Firefox and inject Javascript into it, something similar to what Greasemonkey and Selenium do. It doesn’t have to be for Firefox, it can be a different browser if it is easier.

So what would be the best way to do this?

+4
source share
4 answers

Have you considered Selenium Remote Control ? I have had automatic interaction with the browser using the tool before, and it works very well, providing great flexibility.

Depending on your specific needs, you can use the Selenium IDE , which is an easy-to-use Firefox plugin that makes scripting easy.

+3
source

You can use XPCOM to extend Firefox in every possible way. You could write some kind of interface that might be related to another process.

+2
source

I'm not sure what the β€œbest” way to do this would be, but one possibility is to use AppleScript to work. However, Firefox does not have extensive scripting capabilities - if you want to use Safari, there is an AppleScript command that allows you to enter JavaScript code into the document ( do JavaScript command - look for it in the safari script dictionary, accessible from the Script editor).

In addition, to run AppleScripts from the command line, use osascript :

 osascript path/to/script.scpt 
+1
source

To write scripts on OS X, I would recommend two methods, and both of them are in ruby. The first is Watir , which is an automated testing environment that will control both firefox and safari on Mac os x.

Another, perhaps the best way to clear the screen would be to use hpricot , which is an html parser that is really easy to use.

In the background, Watir uses JSSh, the SSL / Shell server for the TCP / IP browser for Firefox . JSSH allows you to control the browser from a telnet session.

Whatever way you go, if you catch them, they will stop you. This is kind of a goal :-)

0
source

All Articles