1

I am looking for a way how to change the IP address of a network adapter by a script. I am trying pywinauto.

I managed to open the Network and Sharing Center from Windows Control panels. Now I am looking for a way to click on the Change adapter settings link to get the list of my network adapters:

Screenshot highlighting the window element I am trying to click on

So I tried to print the control identifiers of this window by .print_control_identifiers()

import pywinauto

network_cpl = pywinauto.Application(backend="uia").start('control /name Microsoft.NetworkAndSharingCenter')
dlg = network_cpl["Network and Sharing Center"]
dlg.print_control_identifiers()

I have checked in the live debugging console that dlg is actually the dialogue of network_cpl:

network_cpl
<pywinauto.application.Application object at 0x000000000476FDD8>
actions:<pywinauto.actionlogger._StandardLogger object at 0x0000000003BCE630>
backend:<pywinauto.backend.BackEnd object at 0x000000000539B208>
match_history:[]
process:7888
use_history:False
xmlpath:''


dlg
<pywinauto.application.WindowSpecification object at 0x0000000003C0C828>
WAIT_CRITERIA_MAP:{'active': ('is_active',), 'enabled': ('is_enabled',), 'exists': ('exists',), 'ready': ('is_visible', 'is_enabled'), 'visible': ('is_visible',)}
actions:<pywinauto.actionlogger._StandardLogger object at 0x0000000003BCE828>
backend:<pywinauto.backend.BackEnd object at 0x000000000539B208>
criteria:[{'backend': 'uia', 'best_match': 'Network and Sharing Center', 'process': 7888}]

I see that the process ID of the dlg WindowsSpecification object is the same as the process ID of the network_cpl Application object. Yet when I execute dlg.print_control_identifiers() I get this:

Exception has occurred: pywinauto.findwindows.ElementNotFoundError
{'best_match': 'Network and Sharing Center', 'backend': 'uia', 'process': 7888}
4

1 回答 1

1

这是启动器进程生成子进程时的典型问题。未来计划自动检测产卵过程。目前您可以使用

network_cpl.connect(title="Network and Sharing Center")

启动应用程序后。或者通过Desktop对象访问它:

>>> from pywinauto import Desktop, Application

>>> network_cpl = Application(backend="uia").start('control /name Microsoft.NetworkAndSharingCenter')
>>> network_cpl.process
9652
>>> dlg_desktop = Desktop(backend="uia")["Network and Sharing Center"]
>>> found_dlg = dlg_desktop.wrapper_object()
>>> found_dlg.process_id()
15520
于 2018-10-21T13:09:11.787 回答