Intellipaat Back

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

Is it possible to make selenium use the TOR browser? Does anyone have any code they could copy-paste?

1 Answer

0 votes
by (62.9k points)

Yes, it's possible to make selenium use the TOR browser.

I was able to do this on each Ubuntu and macintosh OS X.

Two things have to happen:

  1. Place the binary location(path) to the firefox binary that Tor uses.

On a macintosh this path would generally be /Applications/ On my Ubuntu machine it is /usr/bin/tor-browser/Browser/firefox.

       2. The Tor browser uses a SOCKS host at either through Vidalia or Tor installation.

Launch Tor once from the Finder and leave it open in order that Vidalia is going to be running.

The instances launched with selenium can use the SOCKS host that Vidalia starts, too.

Here is the code to accomplish those two things. I run this on Mac OS X Yosemite:

import os

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

from selenium import webdriver

# path to the firefox binary inside the Tor package

binary = '/Applications/'

if os.path.exists(binary) is False:

raise ValueError("Binary path to Tor firefox is invalid.")

firefox_binary = FirefoxBinary(binary)

browser = None

def get_browser(binary=None):

global browser

# just one instance of a browser opens, remove global for multiple instances

if not browser:

browser = webdriver.Firefox(firefox_binary=binary)

return browser

if __name__ == "__main__":

browser = get_browser(binary=firefox_binary)

urls = (

('tor browser check', ''),

('ip checker', '')


for url_name, url in urls:

print "getting", url_name, "at", url


Using an Ubuntu operating system I ran the Tor browser via selenium.

This machine has tor running at port 9051 and Privoxy hypertext transfer protocol proxy that uses tor at port 8118.

In order for the Tor browser to pass the tor check page, I had to set the HTTP proxy to privoxy.

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

from selenium.webdriver.common.proxy import Proxy, ProxyType

from selenium import webdriver

browser = None

proxy_address = ""

proxy = Proxy()

tor = '/usr/bin/tor-browser/Browser/firefox'

firefox_binary = FirefoxBinary(tor)

urls = (

('tor_browser_check', ''),

('icanhazip', ''),


keys, _ = zip(*urls)

urls_map = dict(urls)

def get_browser(binary=None, proxy=None):

global browser

if not browser:

browser = webdriver.Firefox(firefox_binary=binary, proxy=proxy)

return browser

if __name__ == "__main__":

browser = get_browser(binary=firefox_binary, proxy=proxy)

for resource in keys:


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 training!

Open tor browser with selenium
by (100 points)
for windows, how can i manage it? regards

Browse Categories