Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have googled for the answer, but the ".stop()" so frequently mentioned doesn't work for me. The Chrome window the test was running in remains open.

def test_getResults(self):
    sel = selenium('localhost', 4444, "*chrome", 'http://blackpearl/')
    # do stuff

def tearDown(self):
    sel = selenium('localhost', 4444, "*chrome", 'http://blackpearl/')

Any ideas? I'm using Selenium Server 2.8.0 with Python 2.6 and mostly using Chrome 14 windows to test.


share|improve this question
Is there a quit method? – user246 Oct 11 '11 at 22:21
Yes there is - browser.quit(); Although when I used to run these types of tests before switching to WebDriver I used to have in my TearDown - self.selenium.stop() That usually did it for me. – MichaelF Oct 12 '11 at 13:15
Okay. I will try .quit(). I found that .stop() will stop the server, but not close the window. – Aaron Oct 12 '11 at 17:30
.quit() did not work – Aaron Oct 12 '11 at 17:37
I verified in C# that webdriver.Quit() closes a firefox window, I didn't try it with a chrome driver. – Sam Woods Oct 12 '11 at 23:52

You're actually creating a second Selenium session in your tearDown() function. You need to put the session created in setUp() into an instance variable, then close that session in tearDown().

class TestFoo(unittest.TestCase):
    def setUp(self):
        self.selenium = selenium('localhost', 4444, "*chrome", 'http://blackpearl/')

    def tearDown(self):

    def test_bar(self):"/somepage")
        #and so forth
share|improve this answer

I have worked with Web Driver in both java and C# and I use

In Java :

WebDriver driver;      

In C# :

IWebDriver Driver;
share|improve this answer

Using TestNG and Java. Assume this method is located in some BaseTest class which is inherited by test class, so

@AfterClass(alwaysRun = true) protected void tearDown() { driver.quit(); driver = null; }

share|improve this answer
why the last command? driver=null; – Yash Apr 30 '14 at 6:39
I use it in scope init driver logic, like if null then new driver instance is being creating. That command is optional however. – user1829657 May 5 '14 at 11:56

You can use either driver.close(); or driver.quit();.

Use close() for one browser to close and quit() is to close all browsers using webdriver. But why close() is not closed at runtime, but it is closed at debugging I don't know.

share|improve this answer
Your answer is weak (because you don't give much other information) and doesn't add much to the question and existing answers. You also asked a different question which really should be posted as a separate question (with a lot more information) – Kate Paulk Jun 4 '14 at 10:58
WebDriver driver;      

Above will close all open browser windwos.


WebDriver driver;      

This will close current browser window in focus.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.