2
我试图从微软EDGE浏览器读出标题& URL。 最好的办法是使用System.Windows.Automation,因为代码库已经将其用于其他问题。用System.Windows.Automation读出边缘浏览器标题和网址
- System.Windows.Automation有可能吗?
- 如何访问URL?
我目前这个地步:
AutomationId "TitleBar"
ClassName "ApplicationFrameWindow"
Name = [string]
=> Reading out this element gives me the TITLE
=> Walking it's children, I find the item "addressEditBox":
AutomationId "addressEditBox"
ClassName "RichEditBox"
Name "Search or enter web address"
=> I always get back the string "Search or enter web address"
=> This is the control where the url is in, though it isn't updated as the user goes to a website, it always returns a fixed string.
在代码:
var digger1 = AutomationElement.FromHandle(process.MainWindowHandle).RootElement.FindAll(TreeScope.Children, Condition.TrueCondition);
foreach(AutomationElement d1 in digger1 {
if(d1.Current.ClassName.Equals("ApplicationFrameWindow")) {
var digger2 = d1.FindAll(TreeScope.Children, Condition.TrueCondition);
foreach(AutomationElement d2 in digger2) {
if(d2.Current.ClassName.Equals("Windows.Ui.Core.CoreWindow")) {
var digger3 = d2.FindAll(TreeScope.Children, Condition.TrueCondition);
foreach(AutomationElement d3 in digger3) {
if(d3.Current.AutomationId.Equals("addressEditBox")) {
var url = d3.Current.Name;
return url;
}
}
}
}
}
}
谢谢,请尽快尝试一下!我无法理解System.Windows.Automation API我猜:)...谢谢。 –
此方法仅在EDGE窗口最大化时起作用。如果EDGE最小化,您能建议如何使它工作吗? –
因为如果UIA最小化,UIA不会看到边缘 –