asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.24k forks source link

Fail-safe in EC2 Instance #651

Open miguelcouy opened 2 years ago

miguelcouy commented 2 years ago

Hi everybody, hope you all are safe and healthy, first question here on GitHub. I think I am having a newbie problem about a script I made, which collects very important data about my job and send directly to some groups via Whatsapp (thanks to Selenium, Requests and especially PyAutoGui). My script works in a EC2 Instance on Amazon, running 24/7, and I access via RDP in my notebook. The problem is:

-> During a routine to capture a map from Brazilian National Institute of Meteorologye (INMET), from this url https://mapas.inmet.gov.br/, Selenium works its way to set all filters that I want just fine.

-> When the all filters are are set, the map refreshes with the wanted content. At this point, the map looks like: image

-> But, as you all see, many circles are on top of each other, and I also want a closeup of Brazil's territory (without seeing Africa nor Latin America), as you see at this picture: image

-> So I use the doubleClick(x,y) function to double click in the middle of the screen and zoom up the map: pyautogui.doubleClick(950, 540)

-> It works just fine when I have the RDP window showing up, but when I minimize or close it, the script output this error message: image

-> And when I set the variable pyautogui.FAILSAFE = False, the doubleClick function doesn't happen. I have tried two others modules such as mouse, win32 and both appear to happen the same error. Does pyautogui have anything to solve it?

JayRizzo commented 2 years ago

Hi @fcouy,

I hope you are doing well.

This is an interesting case... You are running the script inside of the Remote desktop. So, when you close it or minimize it, the X, Y coordinates are skewed to a negative or 0, 0 trigging the pyautogui Fail Safe.

As the RDP display size of the monitor changes it appears is adjusting to what you place the window size at. So when you minimize the screen it might be thinking the monitor size is MAX(0,0) instead of (1600,1200) or what ever you had it set to.

If you don't need pyautogui running just exit the program before you minimize the window, thus avoiding the error.

If you do need it running, you may have to do some testing and adjust your window display settings of the RDP.

Good Luck with your testing.

Have a Good Great Day!