How to make the program run from any point of programming

Asked

Viewed 44 times

0

I have a program using pyautogui that fills 20 web formulas sequentially, changing page by page automatically and put a timer for each page of 5 seconds. Usually the pages carry in 2 seconds what gives me a break, but sometimes it takes 20 seconds and the program continues operating running running the functions. I wish I had a line that would let me start qq one of the 20 pages.

import pyautogui
#Pagina 1#
pyautogui.press('tab') # na pagina 1 ele seleciona a caixa de mensagem
pyautogui.write('pagina 1') # escreve "pagina 1" na caixa de mensagem
pyautogui.press('tab', presses=2) # pula até o botao "proxima pagina"
pyautogui.press('enter') # seleciona o botao
pyautogui.sleep(5) # espera 5 segundos ate continuar o proximo comando
#Pagina 2#
pyautogui.press('tab')
pyautogui.write('pagina 2')
pyautogui.press('tab', presses=2)
pyautogui.press('enter')
pyautogui.sleep(5)
#Pagina 3#
pyautogui.press('tab')
pyautogui.write('pagina 3')
pyautogui.press('tab', presses=2)
pyautogui.press('enter')
pyautogui.sleep(5)

If the pages flow with 2 seconds each program finishes the 20 pages normally. If one of them takes too long to load, the program still doesn’t wait. I need something I can stop the program and have the page reset X q piped... Or something that waits for the page to load and just keep going, but I don’t want the option to leave everyone in 20 seconds waiting for the page. Thank you all!

  • 1

    Is the system web? If so, consider using Selenium, which allows you to wait for the page to load.

1 answer

2


So I believe that to automate functions in your browser the recommended library would be Selenium, where you can search for information through the page’s HTML classes. here is the documentation of the Seleniun for you to better understand the application and its functionalities.

However if you want to continue using pyautogui recommend you use the library function pyautogui.locateOnScreen(caminho para foto), the return of this function is the coordinates from where the print was found on the screen you were on at the time, so you generate a repeat loop until the moment it locates on the screen and does the command so no matter how long it takes the response.

is here an example of use

import pyautogui
a = None

while a is None:
      a = pyautogui.locateOnScreen(r'local do arquivo do print.png')

print(a)

but still the Selenium library is the best for this kind of automation, because it was done I will leave an example that exists in the library documentation

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
  • It worked perfectly the way with pyautogui.... includes in each beginning of page command and it got very optimized... now if you click on 1 second or 10, it only starts after loaded and the best, it does not read the print of the current page as the next one, it really waits for the next start! Perfect!!!!

  • 1

    I’m glad I helped, I use this pattern a lot to be able to run on desktop applications on different computers too, so no matter the response time, but the tip is there for future projects Selenium can be extremely useful is more optimized.

  • Would it be possible to put these 3 command lines inside a word? Ex: CARREGAMENTO = a = None
 while a is None:
 a = pyautogui.locateOnScreen(r'C:\>teste.png') Pq when testing outside the site, it does not run the program and I have to go to 20 pages and put # on each command line so that it does not run and can show if the program is running well... If you put it in a word, I would find that word easier and put # before these words

  • I didn’t understand it very well, but to declare variables on a line we usually do like this: variavel1, variavel2 = None, pyautogui.locateOnScreen(r'C:\>teste.png')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.