我想控制当前的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'])
以上正确吗?
如何输入网址?
谢谢。
答案 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}')