我試圖在工作中自動執行任務。我已經有了任務,每次點擊程序就可以完成任務,但是我希望能夠通過點擊幾次完成任務,所以我想使用while來輸入一個循環。於是我開始測試,這是我當前的代碼:使用Selenium的while函數循環拋出錯誤NameError:名稱'neadaclick'未定義
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:')
正如你可以看到我有一個簡單的倒計時,在理論(或至少在我的腦海裏)會發生什麼是的次數,我輸入應該是程序打開瀏覽器並單擊元素startwizard的次數。但是,我不斷收到錯誤needaclick
未定義,我不確定如何正確解決此問題。
錯誤代碼:
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
向我們展示整個錯誤追溯。你讓我們猜猜錯誤發生在哪裏。 –
更新的問題,謝謝你指出。 –
'needaclick = browser.find_element_by_id('startwizard')'vs'neadaclick.click()' - 你能看到它嗎? **需要** vs ** NEAD ** – ElmoVanKielmo