ddeltasolutions / UIDeskAutomation

This is a .NET library that can be used to automate Windows desktop programs based on their user interface. It is created on top of managed Microsoft UI Automation API.
2 stars 1 forks source link

How I can find useful information by using SPY tools? #8

Closed zydjohnHotmail closed 2 years ago

zydjohnHotmail commented 2 years ago

Hello: I recently installed Telegram desktop (Version 4.0) for Windows 10. You can download it here: https://desktop.telegram.org/ Yes, you need a telegram account to login, but it is easy to get one. I want to export some Channels chats to my local hard drive. I can export some channels chats by following instructions, you can see the instructions like this: Open the chat which you want to export. ... Click on the 3 dots at top right. ... In the Chat export settings Window, choose the additional items which you want to export. ... Your export will be completed and Telegram will display the result.

But since I want to export some channels every day, so I want to use your repo to find how I can write some C# code to do the job. But from SPY tools (version 3.0), I can’t see any useful information. I added one small channel, it has only 81 subscribers, so its channel has very few chats. But from SPY tools, almost all the running jobs in Telegram desktop have similar panes, how I can use the SPY tools to find useful information in order to export chat history. Please advise, Thanks, ExportChannel

ddeltasolutions commented 2 years ago

Hi, It looks like this is how the hierarchy of elements is. You just need to use that long descriptor as it is. For example, I wrote this code which is pressing the three dots button in the top-right corner and then chooses "Export chat history": var btn = engine.GetTopLevel("Telegram").GroupAt("", 2).Group("").Group("").Group("").Group("").GroupAt("", 5); btn.Highlight(); btn.Click();

var menuItem = engine.GetTopLevel("TelegramDesktop").Group("").Group("").Group("").Group("").GroupAt("", 5); menuItem.Highlight(); menuItem.Click();

This code was generated on my computer, the descriptors on your pc may be a little different (for ex the top level text). You need to generate the descriptors using the spy.

Best regards.

În mie., 22 iun. 2022 la 16:50, zydjohnHotmail @.***> a scris:

Hello: I recently installed Telegram desktop (Version 4.0) for Windows 10. You can download it here: https://desktop.telegram.org/ Yes, you need a telegram account to login, but it is easy to get one. I want to export some Channels chats to my local hard drive. I can export some channels chats by following instructions, you can see the instructions like this: Open the chat which you want to export. ... Click on the 3 dots at top right. ... In the Chat export settings Window, choose the additional items which you want to export. ... Your export will be completed and Telegram will display the result.

ddeltasolutions commented 2 years ago

Hi, I did a program that clicks on the Options button in Telegram (the three dots button in the top-right corner) then chooses "Export chat history", then (in the window that opens) clicks on "Videos" and then on "Export" button. The code is here:

// Click Options button var optionsBtn = engine.GetTopLevel("Telegram*").GroupAt("", 2).Group("").Group("").Group("").Group("").GroupAt("", 5); optionsBtn.Highlight(); optionsBtn.Click();

// Click "Export chat history" var exportMenuItem = engine.GetTopLevel("TelegramDesktop").Group("").Group("").Group("").Group("").GroupAt("", 5); exportMenuItem.Highlight(); exportMenuItem.Click();

// Click Videos engine.Sleep(1000); var videosCheckbox = engine.GetTopLevel("TelegramDesktop").GroupAt("", 2).Group("").Group("").Group("").Group("").Group("").GroupAt("", 2); videosCheckbox.Highlight(); videosCheckbox.Click();

// Click Export button var exportBtn = engine.GetTopLevel("TelegramDesktop").GroupAt("", 2).Group("").GroupAt("", 2).Group(""); exportBtn.Highlight(); exportBtn.Click();

Best regards.

Message ID: @.***>

zydjohnHotmail commented 2 years ago

Hello: I will do some testing, but I want to know how many channels you have in your Telegram desktop? I have about 18 channels in my program. I need to export 2 of the 18 channels chats every day. If you have only one channel, then the code may be different. But I will try and let you know.

zydjohnHotmail commented 2 years ago

Hello: I wrote a simple C# WinForms App, basically use your code. The following is the C# code: using UIDeskAutomationLib;

namespace DownlooadMP4Form { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

    private void BTNExportChat1_Click(object sender, EventArgs e)
    {
        Engine engine = new();

        var optionsBtn =
            engine.GetTopLevel("Telegram*").GroupAt("",2).Group("").Group("").Group("").Group("").GroupAt("", 5);
        optionsBtn.Highlight();
        optionsBtn.Click();

        // Click "Export chat history"
        var exportMenuItem =
            engine.GetTopLevel("TelegramDesktop").Group("").Group("").Group("").Group("").GroupAt("", 5);
        exportMenuItem.Highlight();
        exportMenuItem.Click();

        // Click Videos
        engine.Sleep(1000);
        var videosCheckbox = 
            engine.GetTopLevel("TelegramDesktop").GroupAt("",2).Group("").Group("").Group("").Group("").Group("").GroupAt("", 2);
        videosCheckbox.Highlight();
        videosCheckbox.Click();

        // Click Export button
        var exportBtn = 
            engine.GetTopLevel("TelegramDesktop").GroupAt("",2).Group("").GroupAt("", 2).Group("");
        exportBtn.Highlight();
        exportBtn.Click();
    }
}

}

When I run it, I got run time error: System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. For this statement: var optionsBtn = engine.GetTopLevel("Telegram*").GroupAt("", 2).Group("").Group("").Group("").Group("").GroupAt("", 5);

I also tried with Console App. I got the same error. The following is the screen shot when running WinForms App, Console App has the black window occupy most of the space. However, it means the engine can't find the Telegram desktop window. I am using Windows 10 version 21H2. Best regards, ExportChannelUISPY01

ddeltasolutions commented 2 years ago

Hi, I noticed that the channels in the left panel cannot be selected individually, it can be selected only the container panel. If the channels you want to export are at a fixed position (for example they are the first two in the list) you can use the ClickAt method on the panel container (like you did with TikTok). You can use the spy tool to get the coordinates where to click.

Best regards.

ddeltasolutions commented 2 years ago

Hi, You need to generate the descriptors on your pc using the spy tool and use those. On Windows 10 the descriptors may be generated differently than on my pc (I have Windows 7). Use the spy tool, pick elements from screen and copy the descriptors in your code. I have one channel with 2 subscribers. But I think exporting the chat history is the same except that you first need to select the channel in the left pane.

Best regards.

Message ID: @.*** com>

ddeltasolutions commented 2 years ago

One more thing, the text of the Telegram top level window changes accordingly to the number of unread messages, so you should use wildcards. For example, instead of GetTopLevel("Telegram (25)") you should use GetTopLevel("Telegram*")

Best regards.

zydjohnHotmail commented 2 years ago

OK, I will spend some time to study this new tools and if I have more issue, I will ask you again. Thanks!

ddeltasolutions commented 2 years ago

You're welcome. Best regards.

În mar., 11 oct. 2022 la 21:25, zydjohnHotmail @.***> a scris:

OK, I will spend some time to study this new tools and if I have more issue, I will ask you again. Thanks!