BadAss
BadAss

Reputation: 61

More the one instance of tor with c#

I am trying to open more then one instance of tor browser with different identities with c#.

One of the brwoswers opens fine:

enter image description here

But when the code opens the second I get empty browser:

enter image description here

Here is my c# code:

IWebDriver browser;

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);
browser =  new FirefoxDriver(profile);
//    browser.Quit();

//Firefox's proxy driver executable is in a folder already
//  on the host system's PATH environment variable.
browser.Navigate().GoToUrl("http://dnsleaktest.com");
//IWebElement header = browser.FindElement(By.Id(“site - header"));

//Assert.True(header.Displayed);
// browser.Close();

Thread.Sleep(10000);
IWebDriver browser2;

FirefoxProfile profile2 = new FirefoxProfile();
profile2.SetPreference("network.proxy.type", 1);
profile2.SetPreference("network.proxy.socks", "127.0.0.1");
profile2.SetPreference("network.proxy.socks_port", 9152);
browser2 = new FirefoxDriver(profile2);
//    browser.Quit();

//Firefox's proxy driver executable is in a folder already
//  on the host system's PATH environment variable.
browser.Navigate().GoToUrl("http://dnsleaktest.com");
//IWebElement header = browser.FindElement(By.Id(“site - header"));

//Assert.True(header.Displayed);
// browser.Close();

Please correct my English if needed

NuGet:

Upvotes: 0

Views: 130

Answers (1)

Ryan Wilson
Ryan Wilson

Reputation: 10765

Change this line:

        //Firefox's proxy driver executable is in a folder already
        //  on the host system's PATH environment variable.
        browser.Navigate().GoToUrl("http://dnsleaktest.com");
        //IWebElement header = browser.FindElement(By.Id(“site - header"));

To this:

        //Firefox's proxy driver executable is in a folder already
        //  on the host system's PATH environment variable.
        browser2.Navigate().GoToUrl("http://dnsleaktest.com");
        //IWebElement header = browser.FindElement(By.Id(“site - header"));

You were navigating the first browser object when you needed to be navigating the second browser object.

Upvotes: 1

Related Questions