我正在尝试使用以下代码在Firefox中获取URL的值。问题是它只返回“搜索或输入地址”(请参见使用Inspect.exe查看树结构)。看起来我需要向下走一层。有人可以告诉我如何做吗。
public static string GetFirefoxUrl(IntPtr pointer) {
AutomationElement element = AutomationElement.FromHandle(pointer);
if (element == null)
return null;
AutomationElement tsbCtrl = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, "Search or enter address"));
return ((ValuePattern)tsbCtrl.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
}
关于树形结构,请参见: