Jean Paul Schutte
Jean Paul Schutte

Reputation: 113

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

I am trying to automate a task in my work. I already have the task and every time I click on the program I can accomplish it, however I would want to be able to do the tasks several times with one click so I want to enter a loop using while. So I started testing, this is my current code:

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:')

As you can see I have a simple countdown and in theory (or at least in my mind) what should happen is that the number of times that I input should be the number of times that the program should open a browser and click on the element startwizard. But, I keep getting the error needaclick is not defined and I am unsure of how to fix this properly.

Error code:

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

Upvotes: 0

Views: 57

Answers (1)

Jean Paul Schutte
Jean Paul Schutte

Reputation: 113

@ElmoVanKielmo pointed out a mistake that i failed to notice, my first declaration is needaclick but on the next line i wrote neadaclick, this has been solved and its working.

Upvotes: 0

Related Questions