-1

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

Redhill
  • 11
  • 3
  • Your problem is that you cannot enter a number? – Matthew Gaiser Jan 31 '20 at 09:39
  • @MatthewGaiser my problem is no.sendkeys does not send my number when the loop returns. – Redhill Jan 31 '20 at 09:42
  • stale element exception is your problem, please check https://stackoverflow.com/questions/12967541/how-to-avoid-staleelementreferenceexception-in-selenium – Mr Cas Jan 31 '20 at 09:44
  • Does this answer your question? [How to avoid "StaleElementReferenceException" in Selenium?](https://stackoverflow.com/questions/12967541/how-to-avoid-staleelementreferenceexception-in-selenium) – Mr Cas Jan 31 '20 at 09:47
  • @MrCas I examined, I tried, but there is no change. – Redhill Jan 31 '20 at 10:29
  • could you update your question with what exactly you have tried (code)? – Mr Cas Jan 31 '20 at 12:44

2 Answers2

1

Add a sleep in the while loop

Clicking login likely changes the page so that the number and password fields no longer exist. You need to have the while pause for a period of time between attempts.

Matthew Gaiser
  • 4,558
  • 1
  • 18
  • 35
0

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.

Redhill
  • 11
  • 3