OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Trouble clicking Tor Browser connect button using Selenium WebDriver

  • Thread starter Thread starter anjoyer
  • Start date Start date
A

anjoyer

Guest
I'm trying to automate interactions with the Tor Browser using Selenium WebDriver in Python. My script launches the Tor Browser successfully with a SOCKS5 proxy, but I'm encountering an issue when trying to click the connect button after the browser loads.

Here's my Python script:

Code:
import time
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


tor_path = r'C:\\Users\\anjoyer\\Desktop\\Tor Browser\\Browser\\firefox.exe'


firefox_options = Options()
firefox_options.binary_location = tor_path


firefox_options.add_argument('--proxy-server=socks5://127.0.0.1:9150')


driver = webdriver.Firefox(options=firefox_options)


def wait_n_reload():
    wait()
    driver.refresh()
    wait()

def wait(min_delay=5.0, max_delay=15.0, variability=0.1):
    base_delay = np.random.normal(loc=(min_delay + max_delay) / 2, scale=(max_delay - min_delay) / 4)
    base_delay = max(min_delay, min(base_delay, max_delay)) 

    micro_delays = np.random.normal(loc=0, scale=variability, size=5)
    total_delay = base_delay + sum(micro_delays)

    if random.random() < 0.05:  
        total_delay += random.uniform(1, 3)

    total_delay = max(0, total_delay)

    time.sleep(total_delay)
    return total_delay


time.sleep(60)
element = WebDriverWait(driver, 60).until(
    EC.element_to_be_clickable((By.XPATH, '//*[@id="connectButton"]'))
)
element.click()




time.sleep(300)

When running the above script, I consistently encounter a TimeoutException when attempting to click the connect button in the Tor Browser. The browser window opens correctly and I've verified that the element is visible and interactable manually. However, Selenium seems to have trouble clicking the button.

Error Message:

Code:
Traceback (most recent call last):
  File "c:\Users\anjoyer\Desktop\torautomation.py", line 46, in <module>
    element = WebDriverWait(driver, 60).until(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\anjoyer\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\support\wait.py", line 105, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:187:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:505:5
element.find/</<@chrome://remote/content/marionette/element.sys.mjs:135:16

What I tried:

Verified the XPath of the "connect" button. Increased WebDriverWait timeout to 60 seconds. Confirmed element visibility and interactability manually. Expected Outcome:

Selenium waits for the "connect" button to be clickable within 60 seconds and successfully clicks it, initiating the connection in the Tor Browser. Actual Result:

TimeoutException is raised when attempting to click the "connect" button, despite its visibility and interactability verified manually.
<p>I'm trying to automate interactions with the Tor Browser using Selenium WebDriver in Python. My script launches the Tor Browser successfully with a SOCKS5 proxy, but I'm encountering an issue when trying to click the connect button after the browser loads.</p>
<p>Here's my Python script:</p>
<pre><code>import time
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


tor_path = r'C:\\Users\\anjoyer\\Desktop\\Tor Browser\\Browser\\firefox.exe'


firefox_options = Options()
firefox_options.binary_location = tor_path


firefox_options.add_argument('--proxy-server=socks5://127.0.0.1:9150')


driver = webdriver.Firefox(options=firefox_options)


def wait_n_reload():
wait()
driver.refresh()
wait()

def wait(min_delay=5.0, max_delay=15.0, variability=0.1):
base_delay = np.random.normal(loc=(min_delay + max_delay) / 2, scale=(max_delay - min_delay) / 4)
base_delay = max(min_delay, min(base_delay, max_delay))

micro_delays = np.random.normal(loc=0, scale=variability, size=5)
total_delay = base_delay + sum(micro_delays)

if random.random() < 0.05:
total_delay += random.uniform(1, 3)

total_delay = max(0, total_delay)

time.sleep(total_delay)
return total_delay


time.sleep(60)
element = WebDriverWait(driver, 60).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="connectButton"]'))
)
element.click()




time.sleep(300)
</code></pre>
<p>When running the above script, I consistently encounter a TimeoutException when attempting to click the connect button in the Tor Browser. The browser window opens correctly and I've verified that the element is visible and interactable manually. However, Selenium seems to have trouble clicking the button.</p>
<p>Error Message:</p>
<pre><code>Traceback (most recent call last):
File "c:\Users\anjoyer\Desktop\torautomation.py", line 46, in <module>
element = WebDriverWait(driver, 60).until(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\anjoyer\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\support\wait.py", line 105, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:187:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:505:5
element.find/</<@chrome://remote/content/marionette/element.sys.mjs:135:16
</code></pre>
<p>What I tried:</p>
<p>Verified the XPath of the "connect" button.
Increased WebDriverWait timeout to 60 seconds.
Confirmed element visibility and interactability manually.
Expected Outcome:</p>
<p>Selenium waits for the "connect" button to be clickable within 60 seconds and successfully clicks it, initiating the connection in the Tor Browser.
Actual Result:</p>
<p>TimeoutException is raised when attempting to click the "connect" button, despite its visibility and interactability verified manually.</p>
 
Top