【发布时间】:2018-04-24 18:11:53
【问题描述】:
我正在使用此代码从 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;
}
有什么方法可以让我也返回当前的个人资料名称?我的意思是在 google chrome 浏览器的右上方可以找到配置文件名称,因此它可能不仅仅是具有不同名称的配置文件,我只想使用来自此函数的 URL 获取当前名称。我可以在 google chrome 中同时打开或使用多个配置文件,因此我想获取活动标签 URL 和配置文件名称以及该配置文件的电子邮件。
这是配置文件名称的图像,我希望它从 chrome 与当前活动的标签 URL 一起发送。
所以我希望类似的事情可以在 c# 中完成以获取配置文件名称 var SearchBar = root.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "profile email"));
最后一件事它可以是 c# 或 java 代码,如果它可以更好地在其中做也可以用任何编程语言获得它的任何解决方案,请帮助提供任何信息。
提前致谢。
【问题讨论】:
标签: java c# google-chrome selenium selenium-chromedriver