为了在firefox中检测URL,我使用了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;
这段代码完美地工作了!但是对于connect(dde.Connect();)来说太慢了7/8秒!
还有另一种方法可以从Firefox获取网址吗? (示例使用API窗口,例如“ SendMessage”)
最佳答案
这对我来说很好:
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;
关于c# - C#从firefox获取URL,但不使用DDE,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15447518/