0

Hi guys I have a hard time making a script.

I have a python script using selenium

I am doing automation on a site, the script needs to be running on that site for a long time.

The problem is that the site times out, the robot returns an error and stops executing.

I need that when this happens close all windows and reconnect to the site again

site timeout is = 30min

if anyone can help me it will help a lot!!!

from selenium import webdriver
import pyautogui

URL = 'https://XXXXXXX'
URL2 = 'https://XXXXXX'

user = 'user12345'
password = 'password12345'
class Web:
  browser = webdriver.Ie(URL)
  browser.find_element_by_name('login').send_keys(user)
  browser.find_element_by_name('password').send_keys(password)

  pyautogui.moveTo(121,134)# here I open a login window so I can use another link that I need to use
  pyautogui.click(121,134)

  browser.execute_script("window.open()")
  browser.switch-to.frame(browser.window_handles[1])
  browser.get(URL2)

  with open(tabela, "r") as leitor:
    reader = csv.DictReader(leitor, delimiter=';')
    for linha in reader:
        folder = linha['folder']
        try:
          browser.find_element_by_id('field').send_keys(folder)
          browser.find_element_by_id('save').click()
        except:
           with open('falied.txt', 'a') as wirter:
                writer.write(folder)
                writer.close()
    browser.quit()
  if __name__ == '__main__':
       Web()

from now on he needs to be running the code inside the page

this code is an example similar to my original code

1 Answer 1

1

Replace your part of code with the code below:

if __name__ == '__main__':
    while True:
        try:
            Web()
        Except:
            browser.quit()

As you can see we're calling it in while True which means it'll run indefinitely browser.quit() will close the selenium.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.