DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
+2 votes

Following the guide Scraping Websites with Python, Selenium, and Tor I don't know how could I wait only until the tor browser is connected instead of waiting a fixed amount of time. Something like what there is in the comment below, which isn't working right now. The torStatus is just an example with doesn't really exist. I'm looking for an actual way to tell when it is connected.

def connect_tor() -> None:
    driver.find_element(By.XPATH, '//*[@id="connectButton"]').click()
    #while driver.find_element(By.XPATH, '//*[@id="torStatus"]').get_attribute("value") != "connected":

3 Answers

0 votes
Best answer

It was easier than I expected:

while driver.find_element(By.XPATH, '//*[@id="connectLongContent"]').is_displayed():

There is also the tor-browser-selenium library to consider.

edited by
0 votes

I don't think it's possible to check when the Tor Browser (Firefox) has established a connection with an Entry Relay. What you can do however is load a page and wait until a certain condition is met. If the page loaded, you know you are connected. This functionality is called "Explicit Wait" in Selenium.

from selenium import webdriver
from import By
from import WebDriverWait
from import expected_conditions as EC

    element = WebDriverWait(driver, 500).until(
        EC.presence_of_element_located((By.ID, "element-id"))
0 votes

If you configure tor browser to connect automatically at startup, you do not need to .click() the connect button. Start the browser and wait until the homepage is loaded.

Contributions licensed under CC0