5

I'm creating test automation for an application. I am using a testing tool to do most of the testing, but in order to get to that point I first need to automate one 'enter' key click in Python. I am using a mac, so pywin32 is not available. Any suggestions?

Roger
  • 141
  • 1
  • 2
  • 4

4 Answers4

1

Appscript makes this pretty easy:

from appscript import app
app('System Events').keystroke('\r')

This will send the keystroke to whichever application is in front.

Zach Kelling
  • 52,505
  • 13
  • 109
  • 108
0
    import time
    from pynput.keyboard import Key, Controller   
    keyboard = Controller()
    # Press and release space
    keyboard.press(Key.space)
    keyboard.release(Key.space)
Pegasus
  • 1,398
  • 15
  • 20
0

By looking around, I found the answer to your question in another question similar to yours.

You're going to have to change up the code a little bit so that it's 'Enter' not Ctrl-r, but it should be easy.

Hope this helps!

Community
  • 1
  • 1
Jeff Gortmaker
  • 4,607
  • 3
  • 22
  • 29
0
import atomacos

def send_multiple_keys(app,keychr):

    """Send multiple key character(Keyboard Key) with no modifiers."""
     """ app here is the bundle id of the application being used"""

    application=atomacos.getAppRefByBundleId(app)
    application.activate()
    application.sendKeys(keychr)

atomacos can be used for automation on mac OS https://pypi.org/project/atomacos/