简体   繁体   中英

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:

在此处输入图片说明

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

在此处输入图片说明

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:

  • NUnit3TestAdapter
  • List itSelenium.WebDriverem

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM