B
B
bluefasik2022-01-10 18:24:14
Python
bluefasik, 2022-01-10 18:24:14

How to stop a loop with selenium?

I have a loop in which actions are performed with selenium.

while loopflag:
  driver.get(link)
  element = driver.find_elements(By.CLASS_NAME, "annonces_entry_link")
  if ads_reg.lower() == "нет":
       print("net")
  else:
              driver.quit()
              loopflag = False

After passing the condition, the loop stops, and selenium continues to work and after a few seconds gives the following error
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=50081): Max retries exceeded with url: /session/2979bc01b96dcad71567dd73a8aac239/element (Caused by NewConnectionError( ': Failed to establish a new connection: [WinError 10061] The connection failed because the destination computer refused the connection request'))

How to make selenium also stop its work and exit the program?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cunning-seal, 2022-01-20
@cunning-seal

wrap the while in a try...except and catch the called exception. in except block - stop selenium

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question