Search code examples
user-interfacepython-3.xmicrosoft-ui-automationpywinauto

Checking a checkbox with pywinauto doesn't work


I installed the last pywinauto module from pip.
I don't know how to use the Check(), UnCheck(), GetCheckState() methods.

This is my very simple code sample.

from pywinauto import application

# Start the madvr settings application.
app = application.Application()
app.start_(r'C:\Program Files\LAV Filters\x86\madVR\madHcCtrl.exe editLocalSettingsDontWait')

# Handle the madvr settings window.
madvr = app.window_(title_re="madVR.*")

# Enable the smooth motion tab.
madvr.TreeView.GetItem(r'\rendering\smooth motion').Click()

# Check the smooth motion checkbox.
madvr.TCheckBox.Check()

It works if I use the Click() method but this is not what I want.

madvr.TCheckBox.Click()

If the checkbox is already checked it unchecks it.

Why I can't use the Check() method?
I tried with Uncheck() and GetCheckState() methods, they didn't work too.


Solution

  • I've added "TCheckBox" class name to make proper check box detection in 0.5.1 (will be released this week). Thanks for the use case. Currently you may workaround it so (code was updated for pywinauto==0.6.x):

    from pywinauto.controls.win32_controls import ButtonWrapper
    checkbox = ButtonWrapper(madvr.TCheckBox.wrapper_object())
    checkbox.get_check_state()