Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help opening certain Chrome tab
#25
The following error messages often appear in practical use:

Au.Types.NotFoundException: Not found.
   at line 68 in _Chrome.cs, Chrome._ATBU_Window(wnd w, wildex wx, Boolean activateWindow)
   at line 40 in _Chrome.cs, Chrome.ActivateTabByURL(String url, Boolean activateWindow)


I encounter these situations while using the code:
1. The Chrome browser window may be minimized.
2. The Chrome browser window may be on the second monitor.
3. There are two Chrome browser windows, each on separate screens (on the first and second monitors).
4. The Chrome browser is not launched.

Code:
Copy      Help
/*/ c _Chrome3; /*/ //.
script.setup(trayIcon: true, sleepExit: true, exitKey: KKey.Pause);
//..

string chromeEXE = @"D:\Chrome\App\chrome.exe";
string url = "www.libreautomate.com/forum/";
string text = @"hello";

Chrome.runLAWeb(chromeEXE, url, text);
 
Code:
Copy      Help
// class "_Chrome3.cs"


//https://www.quickmacros.com/forum/showthread.php?tid=7618&pid=37397#pid37397

static class Chrome
{
    public static void runLAWeb(string chromEXE, string url, string text)
    {

        if (Chrome.ActivateTabByURL(url) == null)
        {

            wnd.findOrRun("*- Google Chrome", "Chrome_WidgetWin_1", run: () => { run.it(chromEXE, url); }, wait: -2);
        }

        
        var w = wnd.find(5, "* - Google Chrome", "Chrome_WidgetWin_1").Activate();
        
        var e = w.Elm["web:TEXT", prop: "@name=keywords"].Find(3);
        
        e.MouseClick();
        
        e.SendKeys("Ctrl+A", 100, $"!{text}", 200, "Enter"); 100.ms();
    }

    
    /// <summary>
    ///
Finds Chrome tab by URL, and activates it.
    /// Searches in all Chrome windows.
    /// </summary>
    ///
<param name="url">URL. Format: wildcard expression.</param>
    ///
<param name="activateWindow">Activete the Chrome window. Default true.</param>
    ///
<returns>Tab info; null if not found.</returns>
    ///
<exception cref="Exception">Something failed.</exception>
    ///
<remarks>
    ///
Temporarily activates each tab (to get its URL) until finds the specified tab. There is no way to avoid it; even Selenium cannot get URL of inactive tabs.
    /// </remarks>
    public static ATBUResult ActivateTabByURL(string url, bool activateWindow = true)
    {

        //wildex wx = url;
        wildex wx = $@"*{url}*";
        foreach (var w in wnd.findAll("*Google Chrome", "Chrome_WidgetWin_1"))
        {

            if (_ATBU_Window(w, wx, activateWindow) is { } r) return r;
        }

        return null;
    }

    
    /// <summary>
    ///
Finds Chrome tab by URL, and activates it.
    /// </summary>
    ///
<param name="wChrome">Chrome window.</param>
    ///
<param name="url">URL. Format: wildcard expression.</param>
    ///
<param name="activateWindow">Activete the Chrome window. Default true.</param>
    ///
<returns>Tab info; null if not found.</returns>
    ///
<exception cref="Exception">Something failed.</exception>
    ///
<remarks>
    ///
Temporarily activates each tab (to get its URL) until finds the specified tab. There is no way to avoid it; even Selenium cannot get URL of inactive tabs.
    /// </remarks>
    public static ATBUResult ActivateTabByURL(wnd wChrome, string url, bool activateWindow = true) => _ATBU_Window(wChrome, url, activateWindow);
    
    static ATBUResult _ATBU_Window(wnd w, wildex wx, bool activateWindow)
    {

        var tablist = w.Elm["PAGETABLIST"].Find(-1);
        var tabs = tablist?.Elm["PAGETAB", flags: EFFlags.HiddenToo].FindAll(); 
        if (tabs?.Any() == true)
        {

            var currentTab = tabs.FirstOrDefault(o => o.IsSelected);
            foreach (var tab in tabs)
            {

                tab.Invoke();
                var doc = w.Elm["web:DOCUMENT", prop: "value=?*"].Find(5);
                var u = doc.Value;
                if (wx.Match(u))
                {

                    if (activateWindow) w.Activate();
                    return new(w, tab, doc, u);
                }
            }

            currentTab?.Invoke();
        }

        return null;
    }

    
    public record class ATBUResult(wnd window, elm tabButton, elm document, string url);
}

The issue persists with missing windows and controls, even with delays set, and it appears randomly.


Messages In This Thread
Help opening certain Chrome tab - by eyescovered - 03-08-2024, 12:03 PM
RE: Help opening certain Chrome tab - by Gintaras - 03-08-2024, 01:32 PM
RE: Help opening certain Chrome tab - by Gintaras - 03-08-2024, 02:12 PM
RE: Help opening certain Chrome tab - by Davider - 03-12-2024, 11:56 AM
RE: Help opening certain Chrome tab - by Gintaras - 03-12-2024, 01:10 PM
RE: Help opening certain Chrome tab - by Davider - 03-12-2024, 11:50 PM
RE: Help opening certain Chrome tab - by Gintaras - 03-13-2024, 05:49 AM
RE: Help opening certain Chrome tab - by Davider - 03-13-2024, 06:24 AM
RE: Help opening certain Chrome tab - by Gintaras - 03-13-2024, 08:01 AM
RE: Help opening certain Chrome tab - by Davider - 03-13-2024, 09:13 AM
RE: Help opening certain Chrome tab - by Gintaras - 03-13-2024, 09:37 AM
RE: Help opening certain Chrome tab - by Davider - 03-14-2024, 05:55 AM
RE: Help opening certain Chrome tab - by Gintaras - 03-14-2024, 06:19 AM
RE: Help opening certain Chrome tab - by Davider - 03-23-2024, 10:51 PM
RE: Help opening certain Chrome tab - by birdywen - 03-24-2024, 01:07 AM
RE: Help opening certain Chrome tab - by Davider - 03-24-2024, 01:33 AM
RE: Help opening certain Chrome tab - by Gintaras - 03-24-2024, 07:25 AM
RE: Help opening certain Chrome tab - by Davider - 03-24-2024, 08:47 AM
RE: Help opening certain Chrome tab - by Davider - 03-25-2024, 11:54 PM
RE: Help opening certain Chrome tab - by Gintaras - 03-26-2024, 04:58 AM
RE: Help opening certain Chrome tab - by Davider - 03-31-2024, 11:52 AM
RE: Help opening certain Chrome tab - by Davider - 03-31-2024, 11:38 PM
RE: Help opening certain Chrome tab - by Gintaras - 04-01-2024, 04:35 AM
RE: Help opening certain Chrome tab - by Davider - 04-08-2024, 01:38 AM
RE: Help opening certain Chrome tab - by Gintaras - 04-09-2024, 05:21 AM
RE: Help opening certain Chrome tab - by Davider - 04-09-2024, 05:39 AM
RE: Help opening certain Chrome tab - by Gintaras - 04-09-2024, 05:45 AM
RE: Help opening certain Chrome tab - by Davider - 04-09-2024, 05:54 AM
RE: Help opening certain Chrome tab - by Davider - 04-13-2024, 07:05 AM
RE: Help opening certain Chrome tab - by Davider - 04-13-2024, 10:59 AM
RE: Help opening certain Chrome tab - by Davider - 04-14-2024, 11:47 PM
RE: Help opening certain Chrome tab - by Gintaras - 04-15-2024, 04:44 AM
RE: Help opening certain Chrome tab - by Davider - 04-15-2024, 05:32 AM
RE: Help opening certain Chrome tab - by Davider - 04-24-2024, 12:21 PM
RE: Help opening certain Chrome tab - by Gintaras - 04-24-2024, 01:02 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)