Как определить URL-адрес, измененный в Google Chrome с использованием System. Windows .Automation - PullRequest
0 голосов
/ 05 августа 2020

Я использую код для получения текущего URL-адреса открытой вкладки Google Chrome. Ниже мой код (с использованием System.Windows.Automation)

public static string GetActiveTabUrl()
    {
        Process[] procsChrome = Process.GetProcessesByName("chrome");

        if (procsChrome.Length <= 0)
            return null;

        foreach (Process proc in procsChrome)
        {
            // the chrome process must have a window 
            if (proc.MainWindowHandle == IntPtr.Zero)
                continue;

            // to find the tabs we first need to locate something reliable - the 'New Tab' button 
            AutomationElement root = AutomationElement.FromHandle(proc.MainWindowHandle);
            var SearchBar = root.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Address and search bar"));
            if (SearchBar != null)
                return (string)SearchBar.GetCurrentPropertyValue(ValuePatternIdentifiers.ValueProperty);
        }

        return null;
    }

Как я могу определить, изменен ли URL-адрес или нет, чтобы я мог снова вызвать метод и получить новый URL-адрес?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...