title: Getting selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id
body: <p>I am getting <strong>Error of selenium.common.exceptions.InvalidSessionIdException: Message: invalid session-id</strong> as soon as I am trying to find CheckboxClick web Element from inside a Function call defined in try block and when I placed below line of code outside the function and try block it will not throw me any error. </p>
  
  <p><strong>Line of Code</strong></p>
  
  <pre><code>try:
      def getrecordsoNpage():
          **CheckBoxclick = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#workflow_table &gt; thead &gt; tr &gt; th.first.checkbox-column.checkbox &gt; input"))).click()**
          RecordsonOnePage = int(driver.find_element_by_css_selector('#wf_table_footer &gt; form.inline.pull-left &gt; div &gt; label &gt; span').text)
          pprint.pprint(RecordsonOnePage)
  
          totalnofpages = math.ceil(TotalNofRecord / RecordsonOnePage)
          print(totalnofpages)
          return RecordsonOnePage,totalnofpages
  
  except RuntimeError as e:
      pprint.pprint(e)
  finally:
      driver.close()
      # driver.quit()
  
  RecordsonOnePage,totalnofpages = getrecordsoNpage()
  pprint.pprint(RecordsonOnePage,totalnofpages)
  </code></pre>
  
  <p>Can Somebody please suggest why it is acting like that and ways I can correct that I have searched for Invalid session-id error and tried to dispose session id but getting the error as explained above. </p>