我需要从chrome(v47.0.2526.106 m(64位))获取活动标签中的URL。 我有一个方法对Firefox / IE有很大帮助,但我的Chrome方法非常慢,60%的时间会崩溃chrome:
public static string GetURL(Process process, string programName, out string url)
{
string temp = null;
if (programName.Equals("chrome"))
{
AutomationElement element = AutomationElement.FromHandle(process.MainWindowHandle);
if (element != null)
{
AutomationElement edit = element.FindFirst(TreeScope.Subtree,
new AndCondition(
new PropertyCondition(AutomationElement.NameProperty, "address and search bar", PropertyConditionFlags.IgnoreCase),
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)));
temp = ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
}
}
url = temp;
return url;
}
所以,对我的问题: 还有其他方法可以有效地执行此操作吗?