代码之家  ›  专栏  ›  技术社区  ›  fleetingbytes

打印网络和共享中心的控制标识符

  •  1
  • fleetingbytes  · 技术社区  · 7 年前

    我正在寻找一种方法,如何改变一个脚本的网络适配器的IP地址。我在试pywinauto。

    我设法从Windows控制面板打开了网络和共享中心。现在,我正在寻找一种方法,单击“更改适配器设置”链接以获取我的网络适配器列表:

    Screenshot highlighting the window element I am trying to click on

    所以我试着用 .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()
    

    我已经在现场调试控制台 dlg 实际上是 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}]
    

    dlg公司 WindowsSpecification对象与 网络cpl dlg.print_control_identifiers() 我明白了:

    Exception has occurred: pywinauto.findwindows.ElementNotFoundError
    {'best_match': 'Network and Sharing Center', 'backend': 'uia', 'process': 7888}
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Vasily Ryabov    7 年前

    当启动程序进程产生子进程时,这是一个典型的问题。将来计划自动检测繁殖进程。当前您可以使用

    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
    
    推荐文章