-2

Idon't know why this is happening. Been trying to fix for sometime now

def Bettings():
    while True:
        if "Rolling in 35." in Label.text:
            Updated_Balance = driver.find_element_by_xpath("""//*[@id="balance"]""")
        if "Rolling in 23." in Label.text:
            Current_Balance = driver.find_element_by_xpath("""//*[@id="balance"]""")

        if "Rolling in 28." in Label.text:

            if Current_Balance < Updated_Balance:

                GrayBetButton.click()
            if Current_Balance > Updated_Balance:
                RedBetButton.click()

Bettings()

Error:

UnboundLocalError: local variable 'Current_Balance' referenced before assignm
  • Possible duplicate of [Local (?) variable referenced before assignment](http://stackoverflow.com/questions/11904981/local-variable-referenced-before-assignment) – user2390182 Mar 02 '16 at 11:24

1 Answers1

2

You define your variable Current_Balance only when you go through the "Rolling in 23." in Label.text 'path'.

When you go directly through the "Rolling in 28." in Label.text path, this variable has not been created yet.

You might want to create this variable at the top, like this:

def Bettings():
    current_balance = 0
    while True:
        if "Rolling in 35." in Label.text:
            updated_balance = driver.find_element_by_xpath("""//*[@id="balance"]""")
        if "Rolling in 23." in Label.text:
            current_balance = driver.find_element_by_xpath("""//*[@id="balance"]""")
        if "Rolling in 28." in Label.text:
            if current_balance < updated_balance:
                grayBetButton.click()
            if current_Balance > updated_balance:
                redBetButton.click()

Bettings()

Note that by convention, variable names tend to start with a non capitalized letter (capitalization is preferred for class names).

DevShark
  • 8,558
  • 9
  • 32
  • 56