Python Global Name True Is Not Defined

Last modified: 
Sunday, March 29th, 2015

Example of Error in Selenium Webdriver Generated Script

ERROR: test_registration (__main__.Registration)
Traceback (most recent call last):
  File "./", line 17, in setUp
    self.accept_next_alert = true
NameError: global name 'true' is not defined


This is a syntax error. Boolean True and False are case-sensitive. Some older code may have them in lower case, which will cause an error in current versions of Python. For example:

    def setUp(self):
        self.driver = webdriver.Firefox()
        self.base_url = ""
        self.verificationErrors = []
        self.accept_next_alert = true


Capitalize the first letter of any boolean declarations.

        self.accept_next_alert = True

The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.