I was able to run the Tor Browser on MacOS using Selenium. First, install the Tor Browser by downloading the appropriate package from here. MacOS will prompt you to move the contents to the Applications folder. Run TorBrowser to see if it works. Leave the TorBrowser running and run the following code.
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary("/Applications/TorBrowser.app/Contents/MacOS/firefox")
driver = webdriver.Firefox(firefox_binary= binary)
driver.get("https://intellipaat.com/")
On Ubuntu, you can just leave the unzipped folder where it is. Test that TorBrowser works by double-clicking the TorBrowser icon in the folder. After spending a lot of time trying to make Tor work with Selenium on Ubuntu, I gave up and concluded that it might be easier to use a different tool specialized for Tor. I tried tor-browser-selenium link, which worked like a charm. This the code from that repository that worked for me:
from tbselenium.tbdriver import TorBrowserDriver
with TorBrowserDriver("/path/to/tbb/tor-browser_en-US/") as driver:
driver.get('https://intellipaat.com')
Prior to running this above code, you may have to export the environment variable TBB_PATH as follows, otherwise, you will get an error stating that TBB_PATH is undefined:
export TBB_PATH=/path/to/tbb/tor-browser_en-US/
If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium 3.0 certification!