2
votes

I am quite new to windows desktop based test automation and also new to python, after spending some good amount of time, pywinauto turned to be an obvious choice to use for windows based application testing using python.

I am using pywinauto to access elements with in a demo app. I have been through related documentation and stackoverflow Q&As, examples on GitHub. This is what I have done

app = Application(backend="win32").start(r"C:\XXX\Bin\XXX.exe")

while not app.Windows_():
    time.sleep(1)

if app.window(title="Start Application - XXX 2.3").Exists():
    app.window(title="Start Application - XXX 2.3").PrintControlIdentifiers() 

The output I get is like this

b'\nHwndWrapper[XXX.exe;;ebf7c21b-5fef-4eb7-a562-3d36735e7519] - \'Start Application - XXX 2.3\'    (L668, T45, R1786, B969)\n[\'HwndWrapper[XXX.exe;;ebf7c21b-5fef-4eb7-a562-3d36735e7519]\', \'Start Application - XXX 2.3HwndWrapper[Zen.exe;;ebf7c21b-5fef-4eb7-a562-3d36735e7519]\', \'Start Application - XXX 2.3\']\nchild_window(title="Start Application - XXX 2.3", class_name="HwndWrapper[XXX.exe;;ebf7c21b-5fef-4eb7-a562-3d36735e7519]")'

I have used swapy tool, but that somehow does not provide available controls and using inspect.exe to check the class names etc.

I checked various other ways, like using findwindows, findwindows.find_element for the child window, to somehow click one a button(did not want to use coordinate) and followed by a by tab click, but none that gave me a suitable control, like what I could find using some paid tool like Test Complete.

Wondering, is it possible to do something like below, using pywinauto

Aliases.XXX.HwndSource_mainWindow.mainWindow.leftToolAreaControl.ToolAreaTabItem.TabControl.ClickTab("Acquisition")

At the moment only thing, I can do is open the app, and using the wrapper close or minimize the app.

Any suggestion would be highly appreciated.

1
If you use Inspect.exe successfully, you need to use backend='uia'. That might be more helpful for modern applications. More details about backends are in the Getting Started Guide.Vasily Ryabov
@VasilyRyabov, thank you for pointing out. With the mentioned approach, now Iam able to get a uiawrapper.Nt sure how to get available controls from an uiawrapper. Been through link Most of the available methods like uiawrapper.expand(), results NULL COM pointer error. Wondering, am I missing some something?arin
It's not a stack trace but a controls tree. You may copy and paste possible attribute name from the second line of every control description in this huge output. For example, here you can use several names from this list: [u'Size on disk:', u'Size on disk:Static', u'Static4']. Of course, it should be corrected to comply with attribute name restrictions, say dlg.Size_on_disk_Static.window_text().Vasily Ryabov
Also note that attribute resolution magic should work across hierarchy. So you may omit some levels and it should search the control inside the subtree.Vasily Ryabov
And one more important thing: window specification can be multi-level, but UIAWrapper can't do attribute access to lower levels. First you need to figure out what is a window specification and how it finds a wrapper.Vasily Ryabov

1 Answers

2
votes

Just to summarize the comments here:

  • If you use Inspect.exe successfully, you need to use backend='uia'. That might be more helpful for modern applications. More details about backends are in the Getting Started Guide.

  • Huge output of print_control_identifiers() is not a stack trace but a controls tree. You may copy and paste possible attribute name from the second line of every control description in this output. For example, here you can use several names from this list:

    [u'Size on disk:', u'Size on disk:Static', u'Static4']

    Of course, it should be corrected to comply with attribute name restrictions, say dlg.Size_on_disk_Static.window_text().

  • Also note that attribute resolution magic should work across hierarchy. So you may omit some levels and it should search the control inside the subtree.

  • And one more important thing: window specification can be multi-level, but UIAWrapper can't do attribute access to lower levels. First you need to figure out what is a window specification and how it finds a wrapper.