如何解决如何通过UI自动化访问DOM模型
我直接从FlaUI库中使用UI自动化框架(https://docs.microsoft.com/en-us/dotnet/framework/ui-automation/ui-automation-overview)。
当我尝试访问Web浏览器窗口内容(例如Chrome)时,我能够检索AutomationElements结构并从框架树访问网页元素。 问题在于,由于树的大小,对于UI自动化而言,访问网页元素的速度太慢。
当前我正在使用这种方法:
...
Automation.AddAutomationFocusChangedEventHandler(OnFocusChangedHandler);
...
this._application = FlaUI.Core.Application.Attach(this.ProcessId);
this._automation = new UIA3Automation();
...
private void OnFocusChangedHandler(AutomationElement elementFocused)
{
...
var mainWindow = this._application.GetMainWindow(this._automation,TimeSpan.FromSeconds(5));
var document = this._mainWindow?.FindFirstChild(p =>
p.ByControlType(FlaUI.Core.Definitions.ControlType.Document));
var someElementOnPage = document.FindAllDescendants(cf =>
cf.ByControlType(FlaUI.Core.Definitions.ControlType.ListItem).And(cf.ByName("SomeName")));
// here I have about 40-50 seconds running query
}
是否可以通过桌面应用程序访问网页内容?
限制是:我需要访问由用户打开的浏览器实例,并且不能修改浏览器和网络设置。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。