TestProject Forum
Powered by leading experts in the test automation community

How to get text from dynamic element in telegram for a new message

Hi , i’ve created steps that gets a number from another sites(web / not mobile) and then searches for the text in telegram (works fine) , but then i’m unable to get text from the searched message as the (div) changes for different messages , so how to get the exact message (get text) for searched number in the telegram (how to find the exact division for searched message) attached image

Hello @srujanpatel9747

To get the text of the div that contains the query you searched for, one possibility is to use a dynamic XPATH that utilizes the DOM of Telegram.
I examined the Telegram Dom and found that every message is contained inside a class which is called ‘im_message_text’.

You can utilize this information to find the message that contains your search query, to do that you can use this XPATH:
//div[contains(., {search_query}) and @class=‘im_message_text’]
Notice that you can parametrize your search query to make it more dynamic.

Use the “Get Text” action on an element with this XPATH to find the message that contains your search query.

This is a reference to how I found about the class of the div that contains telegram messages:

And this is how your action should look like:

You can then save the text contained in that div to an output parameter and use it in your test.

Here are some tips on working with dynamic locators:

Please let us know if you need any further assistance.