如何使用pywinauto连接当前边并输入url?

How to connect current edge using pywinauto and input url?

我想控制当前的 MS Edge 并访问 url,比如说 https://edition.cnn.com/

代码如下:

import pywinauto
import psutil

ids = [p.info for p in psutil.process_iter(attrs=['pid', 'name']) if 'MicrosoftEdge' in p.info['name']]

app = pywinauto.Application().connect(process=ids[0]['pid'])

以上是否正确?

如何输入url?

谢谢。

我能快速找到的唯一方法是使用 Desktop 对象:

from pywinauto import Desktop

d = Desktop(backend='uia')
main_window = d.window(title_re='.*- Microsoft Edge', control_type="Window")
#main_window.dump_tree() # print long output with control identifiers

# after some experiments I could find this is correct edit box
address_edit = main_window.child_window(auto_id="addressEditBox", control_type="Edit")
address_edit.set_edit_text('www.google.com')

# could not find another way to start loading the page yet
address_edit.type_keys('{ENTER}')