Search code examples
pythonpyautogui

pyautogui how to locate image, move to top left of image and then move relative


enter image description here

I'm able to locate the image 'ScheduledBy.png' boxed in black and I can move the mouse the relative distance, but I don't know how to get the mouse to move to the top left of the image first.

Currently when I run it just moves the mouse relative where it's already located

from pyautogui import *

import pyautogui
import time
import keyboard
import random  
import win32api, win32con

    
if pyautogui.locateOnScreen('ScheduledBy.png', confidence=0.9) !=None:
    # need to move x277 y25 relative to top left of 'ScheduledBy.png'
    pyautogui.moveRel(277,25)
    time.sleep(.1)
    pyautogui.click()
    
    
else:
    print("No")

Solution

  • This worked

    from pyautogui import *
    
    import pyautogui
    import time
    import keyboard
    import random  
    import win32api, win32con
    
        
    if pyautogui.locateOnScreen('ScheduledBy.png', confidence=0.9) !=None:
        pyautogui.moveTo('ScheduledBy.png')
        # need to move x277 y25 relative to top left of 'ScheduledBy.png'
        pyautogui.moveRel(277,25)
        time.sleep(.1)
        pyautogui.click()
        
        
    else:
        print("No")