webfp / tor-browser-selenium

Tor Browser automation with Selenium.
MIT License
548 stars 100 forks source link

Issue with running TB-selenium #125

Closed harry0987 closed 4 years ago

harry0987 commented 4 years ago

I installed tbselenium on linux using pip but when i am getting following port error: File "/home/user/.local/lib/python2.7/site-packages/tbselenium/tbdriver.py", line 88, in init_ports % socks_port) TBDriverPortError: SOCKS port 9050 is not listening

I am using tbslelenium with below code:

import unittest from time import sleep from tbselenium.tbdriver import TorBrowserDriver

class TestSite(unittest.TestCase): def setUp(self):

Point the path to the tor-browser_en-US directory in your system

    tbpath = '/home/user/Downloads/tor-browser_en-US/'
    self.driver = TorBrowserDriver(tbpath, tbb_logfile_path='test.log')
    self.url = "https://check.torproject.org"

def tearDown(self):
    # We want the browser to close at the end of each test.
    self.driver.close()

def test_available(self):
    self.driver.load_url(self.url)
    # Find the element for success
    element = self.driver.find_element_by_class_name('on')
    self.assertEqual(str.strip(element.text),
                     "Congratulations. This browser is configured to use Tor.")
    sleep(2)  # So that we can see the page

if name == 'main': unittest.main() ~

Please suggest.

gunesacar commented 4 years ago

Sorry for the late response. This means tor is not listening on port 9050. You can either install it (e.g. by apt install tor) or follow this example to start tor via stem yourself.

gunesacar commented 4 years ago

I updated the README to clarify requirements wrt. to system tor