Unable to run selenium with python using unittest

Home / Uncategorized / Unable to run selenium with python using unittest

macOS Sierra 10.12.4 Python version 2.7 Selenium version 3.5

I’m trying to write a script in Pycharm with selenium webdriver and unittest modules. My goal is to go to a site find the element(button) and click on the button. I tried using Firefox driver and Chrome driver. I also tried to run this without the IDE but no luck. I been searching all over but can’t get to work. Here is my code:

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class HomeWorkTeam(unittest.TestCase):

def setUp(self):self.driver = webdriver.Chrome(executable_path=r’/Users//HomeWork/chromedriver’)

def test_team_search(self):driver = self.driver
teamelem = driver.find_element_by_id("submit")
assert "No results found" not in driver.page_source

def tearDown(self):self.driver.quit()

if __name__ == ‘__main__’:unittest.main()

When I run this this is the output but the browsers does not get launched.

Ran 0 tests in 0.000s


Process finished with exit code 0

I assume you ran it using below
python -m unittest

If your file with this test is myunit then you need to use below to run it
$ python -m unittest -v myunit

test_team_search (myunit.HomeWorkTeam) … ok

Ran 1 test in 6.455s


PS: Refer to https://docs.python.org/devguide/runtests.html for more details
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *