seleniumtortor-browser-bundle

How to run the Tor Browser with Selenium?


I am trying to automate testing of the Tor Browser through Selenium, but as of yet I cannot get it to work. All of my attempts are some sort of variation of the following code:

FirefoxProfile profile = new FirefoxProfile(new File("/Users/MyUsername/Library/Application Support/TorBrowser-Data/Browser/x1v4coki.default"));
profile.setPreference("webdriver.load.strategy", "unstable");
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.socks", "127.0.0.1");
profile.setPreference("network.proxy.socks_port", 9150);
FirefoxBinary binary = new FirefoxBinary(new File("/Applications/TorBrowser.app/Contents/MacOS/firefox"));
FirefoxOptions options = new FirefoxOptions();
options.setBinary(binary);
options.setProfile(profile);
FirefoxDriver driver = new FirefoxDriver(options);

When the last line gets executed, the Tor Browser is successfully started. However, the program will hang for a minute or so and ultimately the following exception will be thrown:

Exception in thread "main" org.openqa.selenium.WebDriverException: connection refused
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: '...', ip: '...', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'
Driver info: driver.version: FirefoxDriver

The same exception is thrown when I omit the profile.setPreference(...) lines. I am using Tor Browser 7.0.8, geckodriver 0.19.0 and Selenium 3.6.

Can someone help me figure out what causes the exception?


Solution

  • Using geckodriver 0.18.0 instead of 0.19.0 solved my problem.