Python Global Name True Is Not Defined

Last modified: 
Sunday, March 29th, 2015
Topics: 
Pythonerrors

Example of Error in Selenium Webdriver Generated Script

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

Cause

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.driver.implicitly_wait(30)
        self.base_url = "http://example.com"
        self.verificationErrors = []
        self.accept_next_alert = true
 

Solution

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.