For detect URL in Firefox I use DDE
DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo");
dde.Connect();
string url1 = dde.Request("URL", int.MaxValue);
dde.Disconnect();
temp = url1.Replace("\"", "").Replace("\0", "");
dde = null;
This code works perfectly! But it is too slow for connect (dde.Connect();
) is too slow 7/8 second!
Is there another way to get URL from Firefox? (example use API windows like SendMessage
)
This works well for me:
AutomationElement element = AutomationElement.FromHandle(intPtr); // intPtr is the MainWindowHandle for FireFox browser
element = element.FindFirst(TreeScope.Subtree,
new AndCondition(
new PropertyCondition(AutomationElement.NameProperty, "Search or enter address"),
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)));
string url = ((ValuePattern)element.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;