Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

How can I install the tor browser to make it useable in Python using Selenium?

I have tried sudo apt-get install tor-browser, but I don't know where it gets installed, hence what to put in the PATH variable (or in executable-path).

My goal is to

  1. install Tor browser

  2. open Tor Browser with Python Selenium

  3. go to a website.

1 Answer

0 votes
by (62.9k points)

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/")

driver = webdriver.Firefox(firefox_binary= binary)


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:


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!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories