Using Selenium WebDriver with Tor

后端 未结 5 905
走了就别回头了
走了就别回头了 2020-11-30 03:12

Because Tor Browser Bundle is just a patched version of Firefox, it seems that it should be possible to use a FirefoxDriver with Tor Browser. This is what I\'ve

5条回答
  •  难免孤独
    2020-11-30 04:05

    This code also is working pretty good in ubuntu. Here is an example (JUnit4):

    package qa2all;
    
    import java.io.File;
    import java.util.concurrent.TimeUnit;
    
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxBinary;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxProfile;
    
    
    public class HTMLUnit {
        private WebDriver driver;
        private String baseUrl;
        private StringBuffer verificationErrors = new StringBuffer();
    
        @Before
        public void setUp() throws Exception {
            //driver = new HtmlUnitDriver();    
            //driver = new FirefoxDriver();
            String torPath = "/home/user/Dropbox/Data/TorBrowser/Linux/32/start-tor-browser";
            String profilePath = "/home/user/Dropbox/Data/TorBrowser/Linux/32/TorBrowser/Data/Browser/profile.default/";
            FirefoxProfile profile = new FirefoxProfile(new File(profilePath));
            FirefoxBinary binary = new FirefoxBinary(new File(torPath));
            driver = new FirefoxDriver(binary, profile);        
            baseUrl = "https://qa2all.wordpress.com";
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        }
    
        @Test
        public void testUntitled() throws Exception {
            driver.get(baseUrl + "/");
    
        }
    
        @After
        public void tearDown() throws Exception {
            driver.quit();
            String verificationErrorString = verificationErrors.toString();
            if (!"".equals(verificationErrorString)) {
                fail(verificationErrorString);
            }
        }
    
        private void fail(String verificationErrorString) {
            // TODO Auto-generated method stub
    
        }
    }
    

提交回复
热议问题