I looked into this, and unless I'm mistaken, on face value it's not possible.
The reason this cannot be done is because:
- Tor Browser is based on the Firefox code.
- Tor Browser has specific patches to the Firefox code to prevent external applications communicating with the Tor Browser (including blocking the Components.Interfaces library).
- The Selenium Firefox WebDriver communicates with the browser through Javascript libraries that are, as aforementioned, blocked by Tor Browser.
This is presumably so no-one outside of the Tor Browser either on your box or over the internet knows about your browsing.
Your alternatives are:
- Use a Tor proxy through Firefox instead of the Tor Browser (see the link in the comments of the question).
- Rebuild the Firefox source code with the Tor Browser patches excluding those that prevent external communication with Tor Browser.
I suggest the former.