Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute resolution #120

Closed
juysu2 opened this issue Nov 13, 2015 · 4 comments
Closed

Attribute resolution #120

juysu2 opened this issue Nov 13, 2015 · 4 comments

Comments

@juysu2
Copy link

juysu2 commented Nov 13, 2015

In reference to documentation: http://pywinauto.github.io/docs/dev_notes.html#attribute-resolution, it say: app.dlg.control

what is the best way to acces to button "Purge": w_customer.tabfolder_customer.tabpage_invoices.tabfolder_years.tabpage_2015.Purge.Click() ?

app.w_customer.Purge.Click() # Exists tabpage_2014, tabpage_2013, ...
or
app.w_customer['tabfolder_customer'].['tabpage_invoices'].['tabfolder_years'].['tabpage_2015'].['Purge'].Click()

@airelil
Copy link
Contributor

airelil commented Nov 13, 2015

It's hard to give a concrete tips without knowing your GUI layout. Generally, I'd suggest you to stick to "Dialog.control" model and break it on several small basic steps. Something as following:

  1. Get app object: app = app.start("path_to_your_app.exe")
  2. Get the main dialog: dlg = app.top_window_() or dlg = app["window title"]
  3. Get a tab control on the dialog: tab_ctrl = dlg["tab control name"]
  4. Select the right tab page: tab_ctrl.Select("tab page name")
  5. Run an action on the control on that page: tab_ctrl.Purge.Click()

Not sure if it applicable for your case but notice that .Net applications currently are only partially supported by Pywinauto.

@vasily-v-ryabov
Copy link
Contributor

app.dlg.control means that control is found in the whole controls tree under the dialog. So further expansion is not supported. If you need to click a button on another tab, you may do something like that:

app.dlg.TabControl.Select("tab name")
app.dlg.Purge.Click()

This is much shorter than following a lot of tabs.

Some debugging tricks can be useful:

  • app.dlg.PrintControlIdentifiers() method prints all available controls with corresponding access name for each one.
  • app.dlg.control.WrapperObject() with just typed . (dot) will give you the most useful list of available methods for the control. There are 2 equivalent constructions: app.dlg.Purge.WrapperObject().Click() (for debugging) and app.dlg.Purge.Click() (for better readable scripts). But app.dlg.Purge is not equivalent to app.dlg.Purge.WrapperObject(). The first one is a description only (the control may not actually exist at some moment), while the wrapper object is for already found control.

@vasily-v-ryabov
Copy link
Contributor

These tips and tricks can be moved to the documentation. So marking the issue as enhancement.

@vasily-v-ryabov
Copy link
Contributor

This is explained in new Getting Started Guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants