如何使用 pywinauto 获取子 window 中的 class 名称?

How to get the class name inside a child window using pywinauto?

我正在尝试使用 pywinauto 自动化应用程序。当我需要定位特定的 window.

时出现问题

比如我想获取window'AfxWnd4214',但是我只能访问window“AfxWnd42”。

   | AfxWnd42 - ''    (L1044, T410, R1060, B426)
   | ['AfxWnd4214', 'V11.82AfxWnd4212']
   | child_window(class_name="AfxWnd42")

   | AfxWnd42 - ''    (L1044, T410, R1060, B426)
   | ['AfxWnd4212', 'V11.82AfxWnd4212']
   | child_window(class_name="AfxWnd42")

我通过这个代码访问它。但不够具体。此 window 的顺序可能会在树中更改。

pywinauto.app.window(class_name = "AfxWnd42", found_index = 0) 

当我尝试这段代码时:

pywinauto.app.window(class_name = "AfxWnd4214", found_index = 0) 

它说

pywinauto.findwindows.ElementNotFoundError: {'class_name': 'AfxWnd4214', 'found_index': 0, 'backend': 'win32', 'process': 15404}

有没有更好的方法来访问这个window?

谢谢。

有多种搜索条件,见下文;尝试组合使用这些。 一旦我使用 auto_id 并且它对我有用。

''' 根据传入的条件查找元素

Possible values are:

* **class_name**     Elements with this window class
* **class_name_re**  Elements whose class matches this regular expression
* **parent**         Elements that are children of this
* **process**        Elements running in this process
* **title**          Elements with this text
* **title_re**       Elements whose text matches this regular expression
* **top_level_only** Top level elements only (default=True)
* **visible_only**   Visible elements only (default=True)
* **enabled_only**   Enabled elements only (default=False)
* **best_match**     Elements with a title similar to this
* **handle**         The handle of the element to return
* **ctrl_index**     The index of the child element to return
* **found_index**    The index of the filtered out child element to return
* **predicate_func** A user provided hook for a custom element validation
* **active_only**    Active elements only (default=False)
* **control_id**     Elements with this control id
* **control_type**   Elements with this control type (string; for UIAutomation elements)
* **auto_id**        Elements with this automation id (for UIAutomation elements)
* **framework_id**   Elements with this framework id (for UIAutomation elements)
* **backend**        Back-end name to use while searching (default=None means current active backend)

'''