Functions of PYAUTOGUI not working

Asked

Viewed 1,706 times

1

I am automating the installation of software using python with pyautogui:

import pyautogui
import time
import pyperclip

for window in pyautogui.getWindows():
    pyautogui.getWindow(window).minimize()

##Abre local do .exe
pyautogui.hotkey("win","r")
pyautogui.press("\\")
pyautogui.press("\\")
pyperclip.copy("ts1/publico/Meus Documentos/Equipes Qualidade/Automação/Aplicativos/Folha/Sefip 8.4")
pyautogui.hotkey("ctrl","v")
pyautogui.press("enter")

##Encontra .exe e da double click nele
executavel = None
while executavel is None:
    executavel = pyautogui.locateOnScreen("executavel.png", grayscale=False)
executalvelX, executavelY = pyautogui.center(executavel)
pyautogui.click(executalvelX, executavelY, clicks=2)

##O instalador abre, aqui ele deveria encontrar o botão 'sim' e clicar nele.
##O Script encontra a posição do botao, porém não clica, não pressiona teclas, não move o mouse.
botaoSim = None
while botaoSim is None:
    botaoSim = pyautogui.locateOnScreen("botaosim.png", grayscale=False)
botaoSimX, botaoSimY = pyautogui.center(botaoSim)
pyautogui.click(botaoSimX, botaoSimY)

for _ in range(4):
    next1 = None
    while next1 is None:
        next1 = pyautogui.locateOnScreen("next.png", grayscale=False)
    next1X, next1Y = pyautogui.center(next1)
    pyautogui.click(next1X, next1Y)

However, at certain stage of the process, some functions like clicking, moving the mouse, pressing a key do not work.

inserir a descrição da imagem aqui

I wonder if I’m doing something wrong, or if it’s because it’s a system installation.

  • The script still running? Error appears?

  • @Andersoncarloswoss The script is still running, no errors, it finds the position of the "yes" and goes on, goes through the for (which is clicking next - also happens the same thing, finds the positions but goes straight through the click)

  • The program will not have lost its focus?

  • I have tested this possibility, but have not succeeded, except if I have done wrong...

4 answers

1

If you install Opencv, you can use the Confidence feature. Sometimes there are small adjustments and modifications in the pixels of an image and decrease the level of accuracy in the search can increase the chances of finding the image you want.

x, y = pyautogui.locateCenterOnScreen('printscreen.png', Confidence=0.8) pyautogui.click(x, y)

0

executavel = pyautogui.locateOnScreen("executavel.png",grayscale=True, confidence=0.9)

Observing:

Grayscale(True) = leaves the image in grayscale, greatly improves recognition Confidence(minimum 0.1 maximum 1.0) = tells the fidelity of the image, closer to the real, varies between 77 and 95 for better results, is an accuracy, the higher the value, the more accurate the image has to be. Obs: use up to 0.9 of very wrong.

0

You can solve this problem like this:

Generate an executable(.exe) from your . py file

Go to File Properties

Squeeze into Compatibility

And mark the box "Run this program as administrator"

0


Hello, Nathan! Sorry to reply a little late, but I’ve been through a similar problem now.

The solution was to simply open the application I wanted to click as Administrator and magically the mouse clicked back on the application screen.

I hope it helps!

Browser other questions tagged

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