What is the process for utilizing or activating a Tor Circuit while in Remote Control mode with Selenium?

I successfully controlled Tor Browser with Selenium, however I soon discovered that the Tor circuits (IP changes) were not enabled. Is there a way to enable them? Or should I use the new feature called "New Identity" from the code?

My setup includes Python 3.7, tbselenium 0.4.2 and Tor Browser 9.0.2. Thank you all for your help.

Answer №1

Below is a sample script demonstrating how to utilize Tor with the chrome webdriver:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.proxy import Proxy, ProxyType

#utilizing Tor for anonymity
from stem import Signal
from stem.control import Controller

link = #insert_url_here
prox='socks5://127.0.0.1:9150' #Establishing connection from Selenium to Tor Port and subsequently to Tor network

while True:

    with Controller.from_port(port = 9051) as controller: #Obtaining a fresh Identity
        controller.authenticate()
        controller.signal(Signal.NEWNYM)

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--proxy-server=%s' % prox) #Configuring connection to your 9150 port alias Tor Network

    #chrome_options.add_argument('--headless') #Launching headless browser
    driver = webdriver.Chrome('*path to your driver file*', chrome_options=chrome_options)
    driver.get(link)
    #performing selenium actions

To make this work, you'll need to install the stem library - essentially Tor's API for Python. Don't forget to tweak the torrc file. Check out this guide on accomplishing all these steps.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Python Selenium - AttributeError: The 'WebElement' object does not possess the attribute 'send_Keys'

Every time I attempt to close the window in Google Chrome, I encounter the following error: from selenium.webdriver.common.keys import Keys browser.find_element_by_tag_name('body').send_Keys(Keys.CONTROL + 'w') However, the error mess ...

Selenium throwing internal server error on specific locators usage

Every time I attempt to find an element without an id but with a class, I encounter the following error: PHPUnit_Extensions_Selenium2TestCase_WebDriverException: Internal server error while executing POST request at http://localhost:4444/wd/hub/session/7b ...

The Webdriverwait function is not behaving as anticipated

My code appears to be correct, however it is not working as expected. Webdriver does not seem to be functioning properly in my code. I am trying to ensure that the page loads completely before navigating back to the previous page. Below is the snippet of ...

Jenkins runs the next script command through sh by utilizing docker.image.withRun

I have a Jenkins script that initiates a Docker container to run Selenium tests using Maven. The tests are successful, and Maven reports "Build Success." The issue arises when Jenkins runs an unknown second command in addition to the specified sh command ...

A step-by-step guide on selecting a checkbox within an alert popup using Selenium with Java

Hello everyone, I am struggling to find a solution for checking and unchecking a checkbox located in an alert window or modal pop-ups. We have three types of pop-ups: alert, confirm, and prompt. Specifically, in the confirm popup, there is a checkbox t ...

Having difficulty printing a browser.find_element_by_xpath using Selenium in Python

I am trying to use the following code: print browser.find_element_by_xpath('/html/body/div[2]/div/div[3]/div/div/div[1]/div[2]/ul/li[4]/ul/li/span[3]/span[3]').text However, I keep getting an unexpected token error on the "browser.find_element_ ...

Encountering a challenge while attempting to execute JavaScript unit tests using Intern with a Chrome Driver on a Selenium Docker Image

I'm attempting to execute my javascript unit tests using Intern with a Chrome Driver on a Selenium Docker Image (Please note that these tests are successful when run locally with versions of Intern and Selenium). I have completed the following 5 steps ...

the function presence_of_all_elements_located does not provide the entire list when used for web scraping using Selenium

Trying to retrieve a complete list of food names from this menu seems to be presenting a challenge. Despite the fact that there are more elements with the specified class name, only 9 items are being retrieved. Utilizing Google Developer tools, it is evi ...

What is the best way to acquire the href value from this source?

Looking to extract the dynamic value "3 Sent" from the html snippet provided. How can this be achieved? <ul class="nav nav-tabs some-tabs"> <li class="active"> <a href="#accepted" data-toggle="tab">1 Accepted</ ...

Locating elements using Ruby Selenium Web Driver without triggering a NoSuchElementException异常

I am currently testing the following HTML using Ruby Selenium Web Driver: <div class="container-fluid container-results"> <div class="result-row" id="0"> <ul> <li class="process-status-column upload-success-ico ...

What steps do I need to take to ensure my Python script functions effectively in the cloud environment?

I have successfully developed a python script that automates the process of booking a gym slot at regular intervals using selenium. While the script works well, I am now looking for a way to run it without having my laptop turned on 24/7. I explored usin ...

Submit fresh text input during selenium operation in asp.net

Currently, in my asp.net project, I am attempting to send data to a Selenium web browser from a web form while the Selenium browser is active. For instance, there is a text box and button on my web form. When I enter text and click the button, it triggers ...

Unable to execute TestNG programmatically due to difficulties in creating an executable JAR file

Looking to create an executable jar file from Selenium TestNG code. import org.testng.TestNG; import com.test.Utility.ExtentReporterNG; public class JarCreator { static TestNG testNg; public static void main(String[] args) { ExtentReport ...

Python Selenium code encounters a "TypeError: this.each is not a function" issue

Currently, I am attempting to extract quotes from Goodreads using a scraping method. The code snippet in question is as follows: from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import Chro ...

Does the WebDriverWait timer reset after running each test case?

I am analyzing the following code snippet: // setting timeout to a COMPLETE MINUTE WebDriverWait wait = new WebDriverWait(driver, 60); Actions action = new Actions(driver); // First, access the usermenu by clicking on it WebElement userMenu = wait.until(E ...

Difficulty locating element using xpath in Java Selenium searchThe xpath search in Java Selenium is

Currently, I have two code snippets that I'm utilizing in order to find dates from a Calendar that includes "From Date" and "To Date". webDriver.findElement(By.xpath("//table/tbody/tr/a[contains(text(),'October 30')]")).click(); ...

Enhancing code suggestions with Selenium2Library in PyCharm

I am currently working on developing a simple library extension for Robot Framework using Python, and my editor of choice is PyCharm. While code completion works well when importing libraries directly, I have encountered an issue when indirectly importing ...

Upon clicking the button in Selenium, a blank page is generated

I have been attempting to populate a text box using Selenium, but I am encountering difficulty locating the text box after clicking on the button to add a new customer. Instead of displaying the expected content, it consistently shows a blank white page. ...

Extracting information from dynamically generated tables using Python 2.7, Beautiful Soup, and Selenium

I am in need of assistance with scraping a JavaScript generated table and saving specific data to a csv file. The tools available to me are limited to python 2.7, Beautiful Soup, and/or Selenium. Although I have referred to the code provided in question 14 ...

Ways to interact with elements lacking an identifier

Currently, I'm faced with an HTML challenge where I need to interact with an element labeled tasks. *<td class="class_popup2_menuitem_caption" unselectable="on" nowrap="">Tasks</td>* In my attempt to do so, I've implemented the foll ...