0

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.

DaiSuki53
  • 15
  • 2
  • 9
  • 1
    Having a poke about with the code in the linked question's answer, I can get the search bar (and thus tabs) with `elmUrlBar = elm.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));` – stuartd Jan 03 '19 at 17:54
  • Duplicate of https://stackoverflow.com/questions/40070703/how-to-get-a-list-of-open-tabs-from-chrome-c-sharp – Manoj Choudhari Jan 03 '19 at 17:56
  • 1
    @ManojChoudhari not a duplicate - none of the (working) answers in that question address the localization issue. – stuartd Jan 03 '19 at 18:02
  • 1
    @ManojChoudhari can't see where it is duplicated. – DaiSuki53 Jan 03 '19 at 18:11
  • @stuartd I can see that you can kind of get to the same result, but how do you find all of the tabs with this? Currently I tried to do that, and what I'm getting is just the main window its URL. – DaiSuki53 Jan 03 '19 at 19:11

0 Answers0