what "self" is doing in the selenium python code?
Question: > **Possible Duplicate:**  
>  [Python ‘self’
> explained](http://stackoverflow.com/questions/2709821/python-self-explained)

I just wrote a code as below with the help of `selenium` documentation, but
confused with one what `self` does some methods `argument list`? Why I need to
import `unittest` class?

    
    
    import unittest
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    
    class PythonOrgSearch(unittest.TestCase):
    
        def setUp(self):
            self.driver = webdriver.Firefox()
    
        def test_search_in_python_org(self):
            driver = self.driver
            driver.get("http://www.python.org")
            self.assertIn("Python", driver.title)
            elem = driver.find_element_by_name("q")
            elem.send_keys("selenium")
            elem.send_keys(Keys.RETURN)
            self.assertIn("Google", driver.title)
    
        def tearDown(self):
            self.driver.close()
    
    if __name__ == "__main__":
        unittest.main()
    


Answer: `self` is used to represent the calling instance of a class in case of member
methods. This is required so that the member methods of a class act on the
correct object. This does not have anything to do with Selenium, but is a
general feature of the language.

It is similar to the `this` argument in C++

When a class is defined, the `self` argument is used when defining data
members of the class as is being done in your class.

