pywinauto / SWAPY

not maintained any more (will be replaced by py_inspect)
https://github.com/pywinauto/py_inspect
271 stars 66 forks source link

`ctrl` variable is not assigned while generating click on toolbar button #44

Open vasily-v-ryabov opened 9 years ago

vasily-v-ryabov commented 9 years ago

It's reproduced on .\apps\MFC_samples\CmnCtrl1.exe. Just open "CToolBarCtrl" tab and run SWAPY.

Find "New" toolbar button and select Click method. The following code is generated:

import pywinauto

pwa_app = pywinauto.application.Application()
ctrl.Button(0).Click()

ctrl is not assigned here. Using ctrl.Button("New").Click() is also better than magic index. Text property is absent at the toolbar button description pane.

moden-py commented 9 years ago

Problem ctrl.Button("New").Click() also actual for ListView and TabControl. Works fine for ComboBox and Menu.

vasily-v-ryabov commented 9 years ago

The same bug for ComboBox item. See CmnCtrl3.exe combo box for reference. I've tried the latest build (x64, release): https://ci.appveyor.com/project/moden-py/swapy/build/1.0.30

Result:

import pywinauto

pwa_app = pywinauto.application.Application()
ctrl.Select('Black')

I expanded combo box items and chose "Select" for "Black" item.

moden-py commented 9 years ago

There is a bug in the code generation for VirtualSWAPYObject. The objects has no own init code they are accessed through the parent. For instance, combobox1.Select('Gray'). No any combobox_item1 var. Added checking for an empty init code. Fixed version - https://ci.appveyor.com/project/moden-py/swapy/build/1.0.32

moden-py commented 9 years ago

resolved in a8b85dd0cf4eb6e18d4824eb6fd0dc6b302b0637

moden-py commented 9 years ago

Using ctrl.Button("New").Click() is also better than magic index. If the "text" is not unique wrong item may be used. Use index access in such cases.

moden-py commented 9 years ago

The fix depends on #66