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不會看到邊緣 –