There are couple of Threads as c# Getting Chrome URL's from all tab to get this solved, but the problem of these are, they're using English Strings to get this solved. I want a way to find the URL and Tab Titles without using any text in some language (for instance, some use "New Tab"). What I've tried as an approach is this:
private void getTabInfo()
{
Process[] processes = Process.GetProcessesByName("chrome");
if (processes.Length == 0)
{
Console.WriteLine("Chrome is not running");
return;
}
foreach (var process in processes)
{
// Ignore process with nullpointer and go to next one.
if(process.MainWindowHandle == IntPtr.Zero)
{
continue;
}
AutomationElement root = AutomationElement.FromHandle(process.MainWindowHandle);
Condition condition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window);
var tabs = root.FindAll(TreeScope.Descendants, condition);
Console.WriteLine(tabs.Count);
// This results in tabs.Count being 0. Awaited: >= 1
}
}
Note I am only searching for the tabs count here, to have a check whether it finds any tabs at all (which is not the case). The root (in the code) seems to be working just fine, so the problem comes after that point.
As an endresult, I like to get all the Tabs' Names and their corresponding URLs.
Thank you in advance.