I want to be notified when certain parts of my screen turns white because that indicates that the page has completed loading and I can carry on. During debugging I realised that pyautogui.pixelMatchesColor doesn't return True when satisfying its parameters.
My original code:
import time
import pyautogui
def wait_until_white_detected_here(x, y):
has_screen_loaded = 0
while has_screen_loaded == 0:
if pyautogui.pixelMatchesColor(x, y, (255, 255, 255)) == True:
has_screen_loaded += 1
else:
time.sleep(0.1)
wait_until_white_detected_here(845, 129)
Further testing indicates that pyautogui.pixelMatch is reading from the correct (x, y)
coordinates.
The part of the screen I was testing was actually white (i.e. RGB = 255, 255, 255). So I moved the screen to a purely white background (also RGB white) so that the (x, y)
coordinates don't matter. But still it wasn't returning True
.
My test code:
import pyautogui
while True:
if pyautogui.pixelMatchesColor(845, 129, (255, 255, 255)) == True:
print("found")
else: print("Not found")
continue
Is it my code screwing up because of an error on my part, or is it just pyautogui
? I have tried uninstalling and reinstalling the package, and still nothing happens.
Very late response, but for some reason this issue was limited to my MacBook, probably because it is a Retina model. This is apparently a known issue. Even though it showed up as (255, 255, 255)
on my PC, it wasn't actually that on my Macbook. Solved by running im.getpixel((x, y))
on my Macbook instead.