How to get pyautogui's click working on mac? - python

pyautogui's click method's issue:
I am running the script from Spyder, if I click anything on Spyder's window the click works fine.
If I execute a script to open Outlook, then click on anything, the click does not happen. Although I am able to use the "moveTo" functionality properly.
Things I have tried as suggested by doing google search:
pyautogui.click()
pyautogui.click()
OS : mac os high sierra
Note:
In order to reach any located image I have to do coordinates/2, as it is a Retina 2x display.
Any workaround or any help will be greatly appreciated.

To anyone who might stumble into the same issue on a Mac, I was able to get it working by using a workaround that is using the pynput library.
Code:
import pyautogui
from pynput.mouse import Button, Controller
mouse = Controller()
pyautogui.moveTo(x,y)
mouse.click(Button.left)

OS X Mojave, the following works for me:
pyautogui.moveTo(pos)
pyautogui.dragTo(button='left')
pyautogui.click() throws an attribute error but pyautogui.dragTo() works instead.

I just found out that in mac setting, I did not check the tip in front of PyCharm in privacy setting. After doing that, my pyautogui.click() function works.

I was also facing same issue, Here is what I tried :
Just add one more line pyautogui.dragTo() to focus on that particular selected area:
pyautogui.moveTo(990,28)
pyautogui.dragTo()
pyautogui.click()

Related

How can I click the close button in Gmail with Python + Selenium?

I want to click on the button to close the message that is being written.
I try with this code, but it does not work for me:
driver.find_element_by_xpath('//input[#type="Cerrar"]').click()
Can you help me? Thanks very much.
You need to click this element: //img[#alt="Close"]
So, the Selenium python command to do this is
driver.find_element_by_xpath('//img[#alt="Close"]').click()
unless your code needs to use selenium i think that pyautogui would be better for this. it can move your mouse to a specific coordinate or look for the close button and then click it
import pyautogui
pyautogui.moveTo(x=(your x), y=(your y))
pyautogui.click()
i dont know much about selenium so im sorry i cant use that to help you but i hope this helps.
The built-in method close:
The close() method is used to close the current browser window on which the focus is set, on the other hand, the quit() method essentially calls the driver. dispose of a method that successively closes all the browser windows and ends the WebDriver session graciously.
You want to use click when interacting with elements
driver.find_element_by_xpath('//input[#type="Cerrar"]').click()
If that doesn't work, please share the HTML code.

Trying to Automate a Keyboard Shortcut, Have Tried both Pyautogui and Keyboard

I'm trying to automated a keyboard shortcut (ctrl+ e) I have tried both pyautogui and the keyboard function, however whenever I run my code instead of executing the shortcut in the application it executes in the command line. It literally just types "e" in the command line and I don't know how to fix this, it's driving me insane.
Literally no one else seems to be having this problem so I'm hoping that I can get an answer here. I have tried:
pyautogui.hotkey('ctrl','e')
keyboard.press('ctrl')
keyboard.press('e')
keyboard.release('ctrl')
keyboard.release('e')
neither have been successful. My system is Darwin 18.6.0 if that helps.
You are almost there. keyboard can do the thing but you are using it the wrong way. You can create combinations using keyboard. Here is how to do it with keyboard:
keyboard.press("ctrl+e")
keyboard.release("ctrl+e")
Make sure to add delay before so that you can switch to your window

Pyautogui bug on mac? triple clicking for no reason when clicking function is used

When I run the pyautogui.click() alone together with time command. I see that the pyautogui.click() command clicks three times everytime the code is being runned... This has been bugging me for 3 days and I have to hand over an assigment today that requires use of this today.
Is this a bug or am I doing something wrong?
import time
import pyautogui
time.sleep(3)
pyautogui.click()
I figured out that it clicked three times by using a virtual keyboard on google that showed how many characters that was produced by the command.

pyautogui - Xlib.error.BadValue

I am using the pyautogui library, and it was working...and for some reason after I reinstalled my Ubuntu system I dont manage to use it.
I show below the code, just several lines copied from the Docs.
The only information about the error, showed in picture I found is this link mentioning "BadValue error", which I dont really understand (100 and 200 are inside range)
https://tronche.com/gui/x/xlib/event-handling/protocol-errors/default-handlers.html
import pyautogui
pyautogui.moveTo(100, 200)
pyautogui.position()
pyautogui.click()
pyautogui.click(100, 200)
Thanks a lot!
Picture with code and execution error
Well, I don't know why this error is coming, because in PyCharm, it works perfectly. But I noticed that the first 3 lines are unnecessary so try this code and tell me if it helps:
from pyautogui import *
click(100, 200)

pyautogui doubleClick not working on OSX

This is my first question so apologies in advanced for everything I'll do wrong in the next lines.
I am having issues with the doubleClick function from pyautogui on mac with OSX.
Lately I have written some python code using the following libraries
from time import sleep
from random import uniform as r
from pyautogui import click, doubleClick, press, moveTo, mouseDown, mouseUp
from webbrowser import open_new_tab
Even by trying the simplest combination
x1, y1 = (300, 375)
doubleClick(x=x1, y=y1)
there is no action taking place. I have tried two quick clicks with an interval, both also got no results from that.
I am experiencing this as a major issues and have checked now on several mac machines (5+) and the issue is always there and I cannot find any reference in other questions or on the internet.
Is anyone else experiencing the same?
Thank you already for your help.
Had the same problem. Found a fix here. (Just make sure you first activated the window you need to double click in, with a single click. I forgot and now it works perfectly.)

Categories