admin管理员组文章数量:1122846
I'm using an M1 MacBook Pro with docker desktop. So this is a Retina display.
I've deployed the jlesage/firefox image in the following way:
docker run -d \
--name firefox \
-p 5800:5800 \
-p 5900:5900 \
-e DISPLAY_WIDTH=1024 \
-e DISPLAY_HEIGHT=768 \
-e DISPLAY=:0 \
-v /Users/vw/DEV/docker/scripts:/scripts \
-e VNC_PASSWORD=password \
jlesage/firefox
It works fine, I can VNC into it and browse and all.
Next I created a python script with pyautogui to find and click the Facebook button:
import os
import pyautogui
import time
# Ensure the script uses the Docker container's display
os.environ["DISPLAY"] = ":0"
# Delay to allow setup
time.sleep(3)
try:
# Locate the image within the Docker display
location = pyautogui.locateCenterOnScreen('Facebook.png', confidence=0.8)
if location:
x, y = location
# Constrain search to 1024x768
if 0 <= x < 1024 and 0 <= y < 768:
print(f"Image found at: {location}")
pyautogui.click(location)
else:
print(f"Image found outside bounds (1024x768): {location}")
else:
print("Image not found on the screen.")
except Exception as e:
print(f"An error occurred: {e}")
The error message I get is: Image found outside bounds (1024x768): Point(x=np.int64(1743), y=np.int64(1145))
so it's not using the display I'm specifying.
I've also exported DISPLAY manually from my terminal.
本文标签:
版权声明:本文标题:python - Trying to automate using pyautogui and docker firefox, but can't stick to the constraints of the display - Stac 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736302218a1931455.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论