Java 当我使用C从Google chrome浏览器获取活动Url时,如何获取活动Google配置文件名#

Java 当我使用C从Google chrome浏览器获取活动Url时,如何获取活动Google配置文件名#,java,c#,google-chrome,selenium,selenium-chromedriver,Java,C#,Google Chrome,Selenium,Selenium Chromedriver,iam使用此代码从Google Chrome浏览器获取当前活动的选项卡打开URL。 public static string GetActiveTabUrl() { Process[] procsChrome = Process.GetProcessesByName("chrome"); if (procsChrome.Length <= 0) return null; foreach (Process

iam使用此代码从Google Chrome浏览器获取当前活动的选项卡打开URL。

 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;
    }
公共静态字符串GetActiveTabUrl()
{
Process[]procsChrome=Process.getProcessByName(“chrome”);

如果(procsChrome.Length你将不得不深入研究一下HTML。使用chrome的开发者功能并检查HTML。你将找到用户名所在的类别,并将文本存储为标题。下面是一个示例

<a class="gb_b gb_ib gb_R" href="https://accounts.google.com/" role="button" tabindex="0" title="Google Account: FillerFirstName FillerLastName (fillerEmail@gmail.com)" aria-expanded="false"><span class="gb_db gbii"></span></a>


你可以用C#以多种不同的方式实现这一点。我建议使用Selenium。

我试图对其进行一些搜索,但没有结果,你能在答案中添加任何代码吗?甚至可以使用Selenium库来获取配置文件名?这里有一个链接可以帮助你理解它。你需要使用findElement关键字。这将允许你可以在上面我的答案中显示的html中找到用户名。一旦找到了对象,你就可以显示包含用户名的标题标签。