[Python] How to Click a Button with PyWinAuto

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to do something (I think) should simple I am trying to select a button named "Start". I have been looking for documentation that describes how-to click a button (with descent example). I have been unable to find any. Anyway here is the error I get:

    Traceback (most recent call last):
    File "C:\Python Scripts\TestVBApp2.py", line 18, in <module>
    vbButton1 = ButtonWrapper(vbapp.Button.WrapperObject("Start")).Click
    TypeError: WrapperObject() takes 1 positional argument but 2 were given


    Here is the code:

    from pywinauto.application import Application
    from time import sleep
    from pywinauto.controls.win32_controls import ButtonWrapper
    import pyautogui
    pyautogui.FAILSAFE = True

    app = Application().Start(cmd_line=u'"C:\\VBPrograms\\SimpleWPFApp.exe"')
    app.MainWindow.Wait('ready')
    vbapp = app.window_(title_re="MainWindow")
    vbButton1 = ButtonWrapper(vbapp.Button.WrapperObject("Start")).Click


    Attached is a screenshot of the app with the "Start" button.

    [​IMG]

    Continue reading...

Compartilhe esta Página