C# 需要捕获当前打开的chrome搜索栏url

C# 需要捕获当前打开的chrome搜索栏url,c#,vb.net,C#,Vb.net,我试过了 AutomationElement elm = AutomationElement.FromHandle(proc.MainWindowHandle); AutomationElement SearchBar = elm.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Address and search bar")); if (Searc

我试过了

AutomationElement elm = AutomationElement.FromHandle(proc.MainWindowHandle);
AutomationElement SearchBar = elm.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Address and search bar"));
if (SearchBar != null)
{
    
    string str = (string)SearchBar.GetCurrentPropertyValue(ValuePatternIdentifiers.ValueProperty);
    return str;
}

但是它花费了太多的时间

提供更多的上下文可能会鼓励其他人给你反馈。例如,在什么环境下运行程序,如何执行程序,以及与预期时间相比,现在需要多长时间。