How to Run Selenium Scripts In Tor Browser?

12 months ago 131

What is Tor? Tor is also known as the Tor Project which is handled by... The post How to Run Selenium Scripts In Tor Browser? first appeared on Abode QA. The post How to Run Selenium Scripts In Tor...

What is Tor?

Tor is also known as the Tor Project which is handled by non-profit organization That handles research on the anonymity and privacy of anyone browsing online. Tor project is designed to prevent government agencies, any company or group of the organization to track the location of the user as well as the browsing habits of the end-user. This project directs all your traffic through thousands of worldwide volunteer overlay networks which consists of more than 7 thousands of relay to conceal the user identity and location from anyone who is performing network surveillance or network analysis.

Using Tor Browser is a medium to take benefits of the Tor Project. These browsers are equally available for desktop, laptop and mobile devices. So Anyone who cares about censorship and privacy could install tor browser on their devices and can save themselves from tracking or surveillance.

How-to-Run-Selenium-WebDriver-Scripts-In-Tor-Browser

What are the benefits of Using Tor Browser?

There are many benefits of using Tor Browser. Here is the list of some of these benefits.

1- Blocks Tracking: Tor Browser isolates each website you visit so third-party trackers and ads can’t follow you. Any cookies automatically clear when you’re done browsing. So will your browsing history.

2- Defense against Surveillance: Tor Browser prevents someone watching your connection from knowing what websites you visit. All anyone monitoring your browsing habits can see is that you’re using Tor.

3- Resist Fingerprinting: Tor Browser aims to make all users look the same, making it difficult for you to be fingerprinted based on your browser and device information.

4- Multi-Layered Encryption: Your traffic is relayed and encrypted three times as it passes over the Tor network. The network is comprised of thousands of volunteer-run servers known as Tor relays.

5- Browse Freely: You can access sites those are blocked in your home network. This provides freedom to access any blocked site even in country like China and many more where government keep track of your every single site visit and activities

How to Run Tor Browser Through Selenium WebDriver?

We have seen in one of the post, how to run brave browser using Selenium WebDriver.. In this post we are going to talk about Tor browser handling through Selenium WebDriver.

Pre-condition

1- Find Path of Tor browser binary. Tor browser is Firefox in its core. So if you are not using WebDriver Manager in that case you need to add gecko driver in System path.
In Windows Path would
C:\Users\<user-name>\Desktop\Tor Browser\Browser\firefox.exe

2- Find path of its profile
In Windows Path would be
C:\Users\<user-name>\Desktop\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default

3- Understanding of WebDriver manager to manage its binary driver.

Steps to Run Script In Tor Browser

Since Tor Browser is based on Firefox Browser. So we need to download geckodriver.exe from its official website as per you machine’s operating system and extract it and provide the path in next step.Set System path
System.setProperty("webdriver.gecko.driver","<Path On Your Machine>/geckodriver.exe" );  
or
in place of Second Step you can use WebDriver manager to handle binary version dynamically.Now we need to Add Binary and Profile in FirefoxOptions

So let’s take one example.
1- We Would be Launching Tor Browser
2- We would be Opening “https://abodeqa.com”
3- We would be clicking on menu.
4- We Would be closing the Tor Browser.

But Before Launching the Tor Browser, Open Tor Browser Manually On you machine and select Auto-Connect Checkbox and establish a connection through Network. This is hack solution which few day back someone has asked me on a mail. For better solution, Might be I will be updating this code in future.

package webdriverExample; import java.io.File; import java.io.IOException; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.firefox.FirefoxProfile; import io.github.bonigarcia.wdm.WebDriverManager; /** * @author Dwarika * */ public class TorBrowserInSelenium { public static void main(String[] args) throws IOException, InterruptedException { // Setting dynamically binary path of gecko driver executable in path WebDriverManager.firefoxdriver().setup(); // Path of Tor Browser Binary String torBinaryPath = "C:\\Users\\dwari\\Desktop\\Tor Browser\\Browser\\firefox.exe"; // Creating Object of FirefoxOptions FirefoxOptions options = new FirefoxOptions(); // Creating FirefoxProfile by providing default Tor Profile. FirefoxProfile fb = new FirefoxProfile(new File( "C:\\Users\\dwari\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default")); // Setting profile to FirefoxOptions. options.setProfile(fb); // Setting binary in Firefox Options. options.setBinary(torBinaryPath); // Creating driver. WebDriver driver; driver = new FirefoxDriver(options); // Maximizing Browser driver.manage().window().maximize(); // Opening Aboceqa site driver.get("https://abodeqa.com"); // Clicking on Manual Testing Menu driver.findElement(By.xpath("//*[@id=\"menu-item-2433\"]/a/span[2]")).click(); // Closing browser instance. driver.quit(); } }

Hope this will help you to open Tor Browser through Selenium WebDriver.

The post How to Run Selenium Scripts In Tor Browser? first appeared on Abode QA.

The post How to Run Selenium Scripts In Tor Browser? appeared first on Abode QA.


View Entire Post

Read Entire Article