如何使用pywinauto和输入URL连接当前边缘?

时间:2019-01-19 13:44:01

标签: python pywinauto

我想控制当前的MS Edge并访问一个网址,例如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'])

以上正确吗?

如何输入网址?

谢谢。

1 个答案:

答案 0 :(得分:1)

我可以快速找到的唯一方法是使用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}')