Why pyautogui click not actually clicking

Question:

I try to use the click function of Pyautogui, but the actual click doesn’t happen or at least there is no change at the page though it moves the mouse to the right place.

The window is in focus (I think) because the program works well with other pages.

I could only find one relevant question: having trouble clicking in program – pyautogui. However, there was no accepted answer for that and I tried the given answer in the link but didn’t work (It was in python2 but I’m in python3).

I use Linux. I have no idea why the mouse moves to the right place but doesn’t perform the click.

The code:

   from selenium import webdriver
   import pyautogui as py
   import time
   import pandas as pd
   browser=webdriver.Firefox()
   browser.maximize_window()
   browser.get("http://jao.eu/marketdata/dailyauctions")
   py.click(x=745,y=692, interval=1)
Asked By: nyaki

||

Answers:

Try editing as follows:

from selenium import webdriver
import pyautogui as py
import time
browser=webdriver.Chrome()
browser.maximize_window()
browser.get('http://jao.eu/marketdata/dailyauctions')
#Allows time for webpage to load
time.sleep(5)
#Set clicks parameter to 2
py.click(x=745,y=692, clicks=2, interval=1)

Setting the clicks parameter to 2 within the click() function will make the chrome browser just opened the active window and the second click will click the link at the coordinates entered in the click() function.

Answered By: Michael

For me I was using my macbook m1. For Macbooks you need to specifically give permissions to control your device.

Go over to
Apple icon on top left -> System Preferences -> Security & Privacy -> Privacy -> Accessibility

Allow the terminal/code editor

If you see it greyed out click on the lock icon below-left of the window and then you should be able to change the permission.

Answered By: Ali Solanki

For windows I am also running my python-code as admin, cause else it won’t recognize the mouse-click.

Also, pyautogui seems to be outdated, I found an upgrade of this library: pydirectinput (https://pypi.org/project/PyDirectInput/)

Answered By: TechyWechy

I opened the application as ADMINISTRATOR and it started to work fine.
I right click cmd.exe and run it as administrator. Then I executed the python script from that window and started to work.

Answered By: Luis Sanchez

You can try something like below:

import pyautogui
import time

pyautogui.moveTo(146,445)
pyautogui.mouseDown()
pyautogui.click()
time.sleep(0.5) 
pyautogui.mouseUp()
Answered By: Ru Yan