4
votes

I am having issues connecting to Tor via Ruby - Watir webdriver.

I use the Tor Browser Bundle. The problem is that when I try to connect via Watir (Selenium) I cannot seem to open Tor instead of regular Firefox.

Looking at similar issues I've tried the following:

require 'watir-webdriver'

profile = Selenium::WebDriver::Firefox::Profile.new

profile['network.proxy.socks'] = '127.0.0.1' #the proxy tor uses
profile['network.proxy.socks_port'] = 9150 #I cannot use 9050, 9150 works when I use Tor
profile['network.proxy.type'] = 1

browser = Watir::Browser.new :firefox, :profile => profile
browser.goto [an .onion website]

When I use the before-mentioned code I nonetheless still open the normal firefox browser, and cannot connect to onion sites.

Any thoughts? Is there another way in which I need to connect the Tor browser to my webdriver profile?

1
I believe the problem is that you have to explicitly tell WebDriver which browser binary to use. Try something iike this: Selenium::WebDriver::Firefox.path = '/path/to/tor/browser/bin'p0deje
You might also need to add WebDriver extension to browser somehow.p0deje
Thanks @p0deje - but what do you mean exactly, to change the binary path? For example: Selenium::WebDriver::Firefox::Binary.path='/path/to/tor/browser/bin' ?Seeb
Selenium::WebDriver::Firefox::Binary.path='/path/to/tor/start-browser-bundle' seems to work! All the profile stuff I have above is no longer necessarySeeb
Please, add the answer then so other people could find it.p0deje

1 Answers

4
votes

The answer:

First, open the Tor browser (it needs to be running already). Then, in your code, make sure to simply start with:

Selenium::WebDriver::Firefox::Binary.path='{location of start_tor_browser*}'
browser = Watir::Browser.new :firefox

*In my case: /home/tor/tor-browser_en-US/start-tor-browser

Nothing else is required - don't bother messing with profile