Looping with while function with Selenium throws error NameError: name 'neadaclick' is not defined

Looping with while function with Selenium throws error NameError: name 'neadaclick' is not defined

我正在尝试使工作中的任务自动化。我已经有了这个任务,每次我点击程序我都可以完成它,但是我希望能够通过一次点击多次完成任务,所以我想使用 while 进入一个循环。所以我开始测试,这是我目前的代码:

from selenium import webdriver
browser = webdriver.Chrome()
def countdown(n):
    while (n >= 0):
#Lets get rid of this
#        print (n)
        browser.get('http://www.simplesite.com/')
        needaclick = browser.find_element_by_id('startwizard')
        neadaclick.click()
        n = n - 1
    print ('Sucess!')
#Change from static to user input.
#countdown (10) 
countdown (int(input('Enter a real number:')))
#Failed script code, leaving it here for documentation
#int(countdown) = input('Enter a real number:')

如您所见,我有一个简单的倒计时,理论上(或者至少在我看来)应该发生的是我输入的次数应该是程序打开浏览器的次数然后单击元素启动向导。但是,我一直收到错误 needaclick is not defined 并且我不确定如何正确解决此问题。

错误代码:

Traceback (most recent call last): File "C:/Users/AMSUser/AppData/Local/Programs/Python/Python35-32/Scripts/Countdown Test.py", line 14, in countdown (int(input('Enter a real number:'))) File "C:/Users/AMSUser/AppData/Local/Programs/Python/Python35-32/Scripts/Countdown Test.py", line 9, in countdown neadaclick.click() NameError: name 'neadaclick' is not defined

@ElmoVanKielmo 指出了一个我没有注意到的错误,我的第一个声明是 neadaclick 但在下一行我写了 neadaclick,这已经解决并且可以正常工作。