2

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:

    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");

Using that code produces this error:

Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed.

I tried referencing this thread for a solution. I then used the following code based off of that thread:

    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");

Using that code launches Tor for me; however, I still receive the same error as before and the driver cannot control that Tor window.

I would appreciate any help or advice.

Community
  • 1
  • 1
IcyPretzel
  • 21
  • 4
  • If you can work without the tor browser, you can tunnel seleniums firefox through tor like this: https://github.com/al-eax/torcontroller/blob/master/examples/src/main/java/de/codebot/torexamples/SocksSeleniumFirefoxClient.java – al-eax Nov 28 '16 at 23:55

0 Answers0