Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to take screenshots for UI element?
#12
I wanted to test a different way, and this is the result. Can get images of any size. Also it seems this is more reliable, never fails.

Code:
Copy      Help
// script "Copy brand logos.cs"
/// https://brandirectory.com/rankings/global/table
/// Copies images from UI elements in Chrome, makes equal size, saves, and displays in the Output panel.

print.clear();
var download = @"C:\Test\logo";
//filesystem.delete(download);
filesystem.createDirectory(download);
int width = 0, height = 30; //edit these if need. If both 0, does not resize. If one 0, preserves aspect ratio. After editing may need to restart LA to reset the Output panel's image cache.

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

HashSet<string> hs = new(StringComparer.OrdinalIgnoreCase);
foreach (var e in w.Elm["web:LINK", "* Brand Logo"].FindAll()) {
    e.Focus(); //focus, scroll
    keys.send("Apps"); //show context menu
    var w2 = wnd.find(5, "", "Chrome_WidgetWin_?", w, contains: "e 'MENUPOPUP'"); //context menu window
    var e2 = w2.Elm["MENUITEM", "Copy image"].Find(3); //context menu item
    clipboard.clear();
    e2.Invoke(); //copy the image to the clipboard and close the context menu
    var b = wait.forCondition(5, () => clipboardData.getImage(png: true)); //get the image from the clipboard
    if (width > 0 || height > 0) b = b.Resize(width, height, BRFilter.Lanczos3, true);
    var name = e.Navigate("pa2 ne").Name; //next cell in this row
    var filename = pathname.correctName(name); while (!hs.Add(filename)) filename += "+"; //create a correct and unique filename
    var path = $@"{download}\{filename}.png";
    b.Save(path);
    b.Dispose();
    print.it($"<>{name}<image \"{path}\">");
}

ScriptEditor.ShowMainWindow(true);


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

Forum Jump:


Users browsing this thread: 2 Guest(s)