title: Running Tor with Selenium webdriver in Java
body: <p>I'm a bit new to selenium and I was looking to use it to run various automated tasks through Tor. I'm on Windows 10 using Java through Eclipse with the Selenium packages as referenced libraries. I've checked out several other tutorials and forum threads detailing how to set up Tor in selenium. I started out trying to use the following code:</p>
  
  <pre><code>    System.setProperty("webdriver.gecko.driver", "D:\\geckodriver-v0.10.0-win64\\geckodriver.exe");
      String torPath = 
              "C:\\Users\\Dave\\Desktop\\Tor Browser\\Browser\\firefox.exe";
      String profilePath = 
              "C:\\Users\\Dave\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default";
      FirefoxProfile torProfile = new FirefoxProfile(new File(profilePath));
      FirefoxBinary binary = new FirefoxBinary(new File(torPath));
      WebDriver driver = new FirefoxDriver(binary, torProfile);
      driver.get("https://www.google.com");
  </code></pre>
  
  <p>Using that code produces this error:</p>
  
  <pre><code>Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed.
  </code></pre>
  
  <p>I tried referencing <a href="https://stackoverflow.com/questions/22978074/using-selenium-webdriver-with-tor/23320554#23320554">this thread for a solution</a>. I then used the following code based off of that thread:</p>
  
  <pre><code>    System.setProperty("webdriver.gecko.driver", "D:\\geckodriver-v0.10.0-win64\\geckodriver.exe");
      String torPath = 
              "C:\\Users\\Dave\\Desktop\\Tor Browser\\Browser\\firefox.exe";
      String profilePath = 
              "C:\\Users\\Dave\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default";
      FirefoxProfile torProfile = new FirefoxProfile(new File(profilePath));
      FirefoxBinary binary = new FirefoxBinary(new File(torPath));
      torProfile.setPreference("webdriver.load.strategy", "unstable");
      try
      {
          binary.startProfile(torProfile, new File(profilePath), "");
      }
      catch (IOException e)
      {
          e.printStackTrace();
      }
      FirefoxProfile profile = new FirefoxProfile();
      profile.setPreference("network.proxy.type", 1);
      profile.setPreference("network.proxy.socks", "127.0.0.1");
      profile.setPreference("network.proxy.socks_port", 9150);
      WebDriver driver = new FirefoxDriver(binary, profile);
      driver.get("https://www.google.com");
  </code></pre>
  
  <p>Using that code launches Tor for me; however, I still receive the same error as before and the driver cannot control that Tor window. </p>
  
  <p>I would appreciate any help or advice.</p>