I am trying to get the value of the URL in Firefox using the following code. The problem is it only returns "Search or enter address" (see tree structure with Inspect.exe below). It looks like I need to go one level down. Can someone show me how to do this.
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;
}
For the tree structure, see:
It's not clear which element you are starting the search from, but you've got two elements with that name. One is a combo box control the other is an edit control. Try using using an
AndCondition
to combine multiple PropertyCondition objects:If the search starts from the combo box, you could instead change
TreeScope.Subtree
toTreeScope.Descendants
since Subtree includes the current element in the search.