Geckodriver allows you to set up a web driver instance in a package like Selenium and control Firefox (and any other Gecko-based browsers).
See the Geckodriver documentation on the Mozilla website.
Downloaded a zip from Releases:
And move the executable to a bin directory in your PATH
.
See this Gist for doing that via a script.
$ brew install geckodriver