I tried the operation with pyautogui on a PC connected with a remote desktop and tried to execute the following code, but when I clicked the icon on the remote desktop, it says "Target not found" I get an error and won't click.

Is there a way to control remote desktop with python code?

Remote desktop icon on desktop
Double click on this

Remote desktop password entry screen
After entering the password in this "Password" field, click the "OK" button below to connect to Remote Desktop



The python source code and each png are in the same folder

import pyautogui as gui
'Double-click the remote desktop connection icon on your desktop
    x, y = gui.locateCenterOnScreen ("./ connectremotedesktop.png")
    gui.click (x, y, clicks = 2)
    # p = gui.position ()
    # gui.click (p, clicks = 2)
'Enter password for connection
    gui.sleep (1)
    gui.typewrite ("password")
'Click the OK button
    x, y = gui.locateCenterOnScreen ("./ btnOK.png")
    gui.click (x, y)
    gui.sleep (5)
'This doesn't work
    x, y = gui.locateCenterOnScreen ("./ IconOnRemotedesktop.png")
    gui.click (x, y, clicks = 2)
except Exception as ex:
    print ("Target not found.")
    print (ex)
The target was not found.
cannot unpack non-iterable NoneType object
  • Answer # 1

    The wallpaper color on the remote desktop is probably the same as the background color of connectremotedesktop.png.
    However, because the background color of IconOnRemoteDesktop.png is different, the target was not found.

    Capture the Firefox icon with the same background color as connectremotedesktop.png and make it IconOnRemoteDesktop.png.

    That should succeed.