WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Automate FireFox

 Keywords:  

Preliminary Information: I Think I've discovered a way to automate Firefox via Winbatch.

It's a round-about process that requires several external items, which means it's not as simple as automating MSIE via OLE. However it's not impossible either.

So far, I've been able to...

  1. Start Firefox and provide a URL as a parameter, this being www.google.com.

  2. Input a search term "Winbatch" and click the "Google Search" button.

  3. Re-direct the page to http://forum.winbatch.com and then login with username & password.

  4. Get the Outer HTML of a page (actually any page so far) but there might be exceptions.

Required 3rd Party Items

Mozlab's MozRepl at http://hyperstruct.net/projects/mozlab The MozRepl must be installed on the PC where Firefox is. You can configure it to start automatically whenever Firefox is started via TOOLS menu --> MozRepl --> Activate on Startup. I believe there is also a command-line switch for Firefox, but I haven't tried it yet. The Mozlab site has an introductory tutorial that's very nice.

According to Google, REPL = "Read Eval Print Loop" and basically you just Telnet into Firefox and send it JavaScript commands which it interprets and then forwards on to Firefox. So it's like an interpreter...sorry for the guess, but I'm learning too.

PUTTY and PLINK at http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html These allow TELNET access to the MozRepl...or you can find your own version elsewhere. PUTTY is nice because this allows you to practice interactively, then you can use PLINK to handle the scripted commands once you have them working. PUTTY can save sessions to a log file which can be handy. I suggest you place these two EXEs in your system's path to expedite their use.

A working knowledge of JScript or JavaScript as that's what the REPL uses to communicate with the Mozilla DOM. I'm a beginner but somewhat crafty enough to steal code from a variety of sources :) Good news is that the REPL doesn't require the ; at the end of lines, but will accept them, so cutting and pasting from an already working script is fair game. Another big plus is that you can create a library of .js functions, place them all in a .js file and then tell REPL to include this file when it's working. Since Mozilla DOM offers no .outerHTML property, I was able to find and dump Function getOuterHTML(node) and include this in my MozRepl startup so that I have access to it.

Knowledge of the Mozilla DOM which is incredibly different from the MSHTML one. However there is this resource... http://www.mozilla.org/docs/dom/ which I've been raiding over and over. Get ready for some confusion. Don't forget that using JScript and JavaScript requires getting the case/capitalization of Keywords right and not forgetting things like the () on functions like object.click() and others. If you locate a better DOM resource, please share it !

Java Development Kit not absolutely necessary, especially if you have a package that can deal with .JAR files and extract their contents. I went this route just to be sure. You can then go into Firefox, and other JAR files, extract .js files and then dump and examine their source to work with it via the REPL. You can download this free from http://java.sun.com/javase/downloads/index.jsp and then make use of the JAR.EXE utility to list and extract JAR file contents. I used the JDK 6 Update 6 item. Another handy item is a GREP utility, because once you have all these .js files, you're going to need a way to look for "^function " and so on, to see if someone's already got what you need.

Winbatch DOM Extender a 3rd party winbatch extender, but this will then let you parse data you download from sites. You can get it from: http://www.graphicaldynamics.com/wxdom/wxdom44i.zip

So the process is not for the feint of heart or beginner -- but you have to start someplace. It also might not work in all circumstances (meaning projects you come across).

Things you can't do you can't make Firefox "interactive" with the user, at least not yet! ;) You can navigate to blank pages and .open() the document and .write() to it but so far I don't see a way to acknowledge any actions by the user. I suggest sticking to MSIE or WBT Dialogs using MSHTML: or Shell.Explorer, et al for automating an interactive session.

Basic Steps

Here's what my first script looks like:

ff = "firefox.exe"
Run(ff, "http://www.google.com")

pwn = "~Google - Mozilla Firefox"
While !WinExist(pwn)
   TimeDelay(1)
EndWhile

Display(3, ff, "Loaded")

comspec = Environment("COMSPEC")
RunHideWait(comspec, "/c plink -raw -batch -P 4242 localhost < Google-Search.txt")

Display(2, ff, "Redirecting to WinBatch Forum")

RunHideWait(comspec, "/c plink -raw -batch -P 4242 localhost < WBT-Redirect.txt")

Display(2, ff, "Logging In")

RunHideWait(comspec, "/c plink -raw -batch -P 4242 localhost < WBT-Login.txt")
The Google-Search.txt, WBT-Redirect.txt and WBT-Login.txt files simply contain JavaScript and REPL commands to automate firefox. The commands are redirected into plink from the file, which executes them in the telnet session. The display() statements allow the browser to load the new page (these are simple queries and redirects) before the next set of commands are executed.

Once I get more sophisticated with Mozilla DOM it'll probably be easier to incorporate 2 or 3 or more small command files into a single one.


Article ID:   W17906
Filename:   Automate FireFox.txt
File Created: 2013:06:19:15:13:42
Last Updated: 2013:06:19:15:13:42