Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to take screenshots for UI element?
#8
Code:
Copy      Help
// script "Capture brand logos.cs"
//https://brandirectory.com/rankings/global/table

print.clear();
filesystem.createDirectory(@"C:\Test\logo");

var w = wnd.find(0, "Global 500 2023 | Brand Value Ranking League Table | Brandirectory - Google Chrome", "Chrome_WidgetWin_1");
w.Activate();
keys.send("Ctrl+Home");
500.ms();

using var ci = new CaptureScreenImage();
for (int i = 2; i < 500; i++) {
    gRetry:
    var e = w.Elm["web:DOCUMENT", navig: $"fi3 ch5 fi3 ch{i} ch3 fi3"].Find(1);
    ci.Capture(e.Rect);
    
    var a = ci.ToArray2D();
    if (a[ci.Height - 1, 0] == 0xFF000000) { //if the bottom-left pixel is black
        //print.it(i);
        //scroll to the next element, because Chrome does not scroll to this element if it is partially visible

        e = w.Elm["web:DOCUMENT", navig: $"fi3 ch5 fi3 ch{i + 1} ch3 fi3"].Find(1);
        e.ScrollTo();
        50.ms();
        goto gRetry;
    }

    
    using var bitmap = ci.ToBitmap();
    var ms = new MemoryStream();
    bitmap.Save($@"C:\Test\logo/{e.Name.Split("/")[0]}.png");
    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
    print.it($"<><image \"image:{Convert.ToBase64String(ms.ToArray())}\">");
}

ScriptEditor.ShowMainWindow(true);

//Several times noticed 1 or several white or almost white images captured.

//Once Chrome UI elements stopped working. Restart Chrome.


Messages In This Thread
RE: How to take screenshots for UI element? - by Gintaras - 05-13-2023, 02:43 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)