Warm tip: This article is reproduced from stackoverflow.com, please click
loops python selenium while-loop

I can't run the while loop

发布于 2020-03-28 23:14:00

I just started python. I want to write a loop containing bot using Selenium. I want to login to a site. I send my number and password. The page refreshes when there is density on the server. Number and password sections are being cleaned. I want it to try to login with the same number and password until I log in to the system. If I enter text in the number section, the loop works, but I need to enter a number.

from selenium import webdriver
import time
browser = webdriver.Chrome()
browser.get("https://www.*****.com")
time.sleep(1)

loginbutton = browser.find_element_by_name('login')
no = browser.find_element_by_name('no')
password = browser.find_element_by_name('pass')

while True:
    no.send_keys("160210051")
    password.send_keys("example")
    time.sleep(1)

    loginbutton.click()
    no.clear()
    password.clear()
    continue

python shell, error descripton

Questioner
Redhill
Viewed
84
Redhill 2020-02-03 20:07

I found finding elements in the while loop and it worked. The elements in the past are deleted after the page is refreshed. Thanks everyone.