I am working on a script that accepts the game of league of legends automatically, then moves to the chat dialogue to call the lane. This worked fine for the click_accept() function, prints out the x,y coordinates perfectly. However the print(pos.x/2,pos.y/2) line for click_chat_dialog() gives me the following error:
AttributeError: 'NoneType' object has no attribute 'x'
Here is my code:
import pyautogui, time, os, logging, sys, random, copy
def imPath(filename):
return os.path.join('images', filename)
def click_accept():
if pyautogui.locateOnScreen(imPath('accept_button.png'), confidence=0.8) != None:
pos = pyautogui.locateCenterOnScreen(imPath('accept_button.png'))
print(pos.x/2,pos.y/2)
pyautogui.moveTo(pos.x/2,pos.y/2)
time.sleep(0.5)
pyautogui.click(pos.x/2,pos.y/2)
def click_chat_dialog():
if pyautogui.locateOnScreen(imPath('chat_dialog.png'), confidence=0.6) != None:
pos = pyautogui.locateCenterOnScreen(imPath('chat_dialog.png'))
print(pos.x/2,pos.y/2)
pyautogui.moveTo(pos.x/2,pos.y/2)
time.sleep(0.5)
pyautogui.click(pos.x/2,pos.y/2)
while 1:
click_accept()
click_chat_dialog()
Here are the images I am using:
Accept Button - https://i.imgur.com/1vW6cp3.png
Chat Dialogue - https://i.imgur.com/PwdXii3.png
Accept Screen - https://i.imgur.com/xOeLTmq.png
Chat Screen - https://i.imgur.com/LfZQCnR.png