OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to Click a Button with PyWinAuto

  • Thread starter Thread starter Lyle Lacey
  • Start date Start date
L

Lyle Lacey

Guest
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:

Code:
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:

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.

enter image description here

<p>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:</p>

<pre><code>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
</code></pre>

<p>Here is the code:</p>

<pre><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
</code></pre>

<p>Attached is a screenshot of the app with the "Start" button.</p>

<p><img src="https://i.sstatic.net/JrEIC.png" alt="enter image description here"></p>
 
Top