title: Selenium Python error 'object has no attribute driver'
body: <p>I have two files one is <code>Login_test.py</code> and the other is <code>Financial_Account_Balance.py</code>. When I run the Login file, it works but I want after the system Login, it should check the Financial Account. I keep getting error when I instantiate the Class in the Financial Account Script.</p>
  <pre><code>Object has no attribute 'driver'
  </code></pre>
  <p><strong>Below is my code for both files</strong></p>
  <p><strong>Login_test</strong></p>
  <pre><code>import unittest
  from selenium import webdriver
  import time
  
  
  class LoginForm(unittest.TestCase):
  
      def __init__(self, driver = None):
  
          #super().__init__(driver)
          if driver is not None:
              self.driver = driver
          else:
              self.setUp()
  
  
      def setUp(self):
  
          self.driver = webdriver.Chrome(executable_path=r&quot;..\browser\chromedriver.exe&quot;)
          print(&quot;Running Set Up method&quot;)
          print(self.driver)
  
          self.test_result = None
  
  
      def test_Login(self):
          # We wrap this all in a try/except so we can set pass/fail at the end
  
          try:
              # load the page url
              print('Loading Url')
              self.driver.get('http://localhost:4200/')
  
              # maximize the window
              #print('Maximizing window')
              self.driver.maximize_window()
  
              # we'll start the login process by entering our username
              print('Entering username:')
              self.driver.find_element_by_name('username').send_keys('mobile@******.com')
  
              # then by entering our password
              print('Entering password:')
              self.driver.find_element_by_id('pass').send_keys('*****')
  
              # now we'll click the login button
              print('Logging in')
              self.driver.find_element_by_class_name(&quot;submit&quot;).click()
  
              time.sleep(25)
  
              self.test_result = 'pass'
  
          except AssertionError as e:
              # log the error message
              self.test_result = 'fail'
              raise
  
  &quot;&quot;&quot;
      def tearDown(self):
          print(&quot;Done with session&quot;)
          self.driver.quit()
  &quot;&quot;&quot;
  
  if __name__ == '__main__':
      unittest.main()
  </code></pre>
  <p><strong>Financial Account File</strong></p>
  <pre><code>from Unit_Test_Files.Login_test import *
  from selenium.webdriver.support import expected_conditions as EC
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.support.ui import WebDriverWait
  from selenium.webdriver.common.by import By
  import time
  import logging
  import unittest
  
  
  class FinancialAccountBalance:
  
  #logf = open(&quot;Financial_Account_Balance_exception.log&quot;, &quot;w&quot;)
  
  
      def __init__(self, driver = None):
          if driver is not None:
              self.driver = driver
          else:
              print('Financial Account Balance Testing Started...')
              self.test_finacial()
  
      def setUp(self):
          print(self.driver)
          print(&quot;setup method running&quot;)
          self.test_finacial()
  
      def test_finacial(self):
        try:
          print(self.driver)
          self.driver.find_element_by_xpath(
              '/html/body/chankya-app/chankya-layout/div/ng-sidebar-container/div/div/section/div/div[2]/app-home/div/div/div/div/div[2]/div/input').send_keys(
              'Financial Account Balance')
          time.sleep(2)
          self.driver.find_element_by_xpath(
              '/html/body/chankya-app/chankya-layout/div/ng-sidebar-container/div/div/section/div/div[2]/app-home/div/div/div/div/div[2]/div/input').send_keys(
              Keys.ENTER)
          time.sleep(2)
  
          WebDriverWait(self.driver, 10).until(
              EC.presence_of_all_elements_located(
                  (By.XPATH, '//html/body/chankya-app/chankya-layout/div/ng-sidebar-container'
                             '/div/div/section/div/div[2]/app-home/div/div/div/div/div[4]'
                             '/div/div/table/tbody/tr')))
          result = self.driver.find_element_by_xpath(
              '(/html/body/chankya-app/chankya-layout/div/ng-sidebar-container/div/div/section/div/div[2]/app-home/div/div/div/div/div[4]/div/div/table/tbody/tr)[1]')
          result.click()
  
          time.sleep(15)
  
          logging.basicConfig(filename='Financial_Account_Balance.log', level=logging.INFO, filemode='w',
                              format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p ')
          logging.info('Date and Time \nReport: Financial Account Balance Automation Test is Successful!!! \n')
          print('Financial Account Balance Automation Test is Successful!!!')
  
        except AssertionError as e:
          # log the error message
          self.test_result = 'fail'
          raise
  
  
      def test_verify(self):
          lf = LoginForm()
          lf.test_Login()
          self.test_finacial()
  
  if __name__ == '__main__':
      fa = FinancialAccountBalance()
      fa.test_verify()
  </code></pre>
  <p><strong>Error I get when I run the Financial Account file</strong></p>
  <pre><code>&quot;C:\Users\Apollo Universe IDS\.virtualenvs\test-cM_nBYrn\Scripts\python.exe&quot; C:/Users/Public/Documents/test/Financial_Module/Financial_Account_Balance.py
  Financial Account Balance Testing Started...
  Traceback (most recent call last):
    File &quot;C:/Users/Public/Documents/test/Financial_Module/Financial_Account_Balance.py&quot;, line 68, in &lt;module&gt;
      fa = FinancialAccountBalance()
    File &quot;C:/Users/Public/Documents/test/Financial_Module/Financial_Account_Balance.py&quot;, line 21, in __init__
      self.test_finacial()
    File &quot;C:/Users/Public/Documents/test/Financial_Module/Financial_Account_Balance.py&quot;, line 30, in test_finacial
      print(self.driver)
  AttributeError: 'FinancialAccountBalance' object has no attribute 'driver'
  </code></pre>