0

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?

Gertjan Franken
  • 596
  • 1
  • 5
  • 24
  • 2
    Don't use geckodriver with tor as geckodriver is made for newer FF versions & tor is older FF fork. Refer https://stackoverflow.com/questions/39134419/run-tor-browser-with-selenium-webdriver – Mahesh Karia Nov 01 '17 at 18:31
  • Thanks for your suggestion, but I need geckodriver to operate the Tor Browser through Selenium. I already encountered the link you mentioned and I tried the same solution. However, I got it to work using geckodriver 0.18.0 instead of 0.19.0. – Gertjan Franken Nov 03 '17 at 14:19
  • Have you tried this with the newest Geckodriver 0.20? – Arya May 02 '18 at 19:07

1 Answers1

0

Using geckodriver 0.18.0 instead of 0.19.0 solved my problem.

Gertjan Franken
  • 596
  • 1
  • 5
  • 24