Announcements
Hi all, hope everyone is doing well!
I had a question that I hoped someone can help me with.
Is it possible to save a Selector value into a variable?
Many thanks in advance for answering!
Hi @Tjan ,
Yes, it is possible to save a Selector value into a variable in Power Automate Desktop. Here are the steps you can follow:
1.Search for the element that needs to be edited in the UI elements pane, right click on the element and go to edit selectors.2.Navigate to the selector builder which can be used to easily customize the selector and click on the “custom” toggle button.3.Now for your case you would need to parse the variable %var_row% in the table selector attribute1. For instance, if you have a selector like this: window [Class="#32770"] [Name="New Invoice"] > list [Class="SysListView32"] > listitem [Id="ListViewItem- %row_nr% "] > text [Id="ListViewSubItem- %col_nr% "], you can replace %row_nr% and %col_nr% with your variables.
(Note:- if you got your solution you can mark as solution and gives kudos)
Thanks & Regards
Vishnu Reddy
@VishnuReddy1997 I appreciate your response! However, your solution looks like you are saving a variable into a selector (instead of the other way around). Is my assumption correct?
You’re correct, and I apologize for the confusion. The previous explanation was about how to use a variable in a selector.
To save a selector value into a variable in Power Automate Desktop, you can try as below.
@VishnuReddy1997 Hi Vishnu, once again thanks! Unfortunately this is also not what I am seeking.
I try to rephrase since I was a bit vague I think. For instance, I have a selector with value "ABC". I want to set this ABC value into a variable called var1.
Is that possible?
I have done the same thing i have selector like 'button[id="hdrSrch]' and i have assigned to the variable called Selector using Set Variable.
@VishnuReddy1997 Here 'button[id="hdrSrch"]' is hardcoded right? Or is it a reference to an actual selector in your flow?
Its a actual selector. Its a selector for clicking search bar in different website.
Regards,
Hi @Tjan !
So let me guess what you are trying to say.
Let's say I already have the Xpath in those UI elements maybe already captured before. So what you want to do is to fetch the content of the UI element i.e. the Xpath of that UI element and store that in a variable. Is that right?
If yes, what particular use case are you looking forward using this idea?
Hi @NathanAlvares24 , this is absolutely correct! I need this because a selector references a row and column that I need for another selector. I've tried the usual ways but there's no way to do this properly unfortunately.
@Tjan
Please follow the below approach:
Launch Microsoft Edge Browser:
Set Initial Column Number:
Loop Through Table Rows:
Construct the XPath for Each Cell:
Execute JavaScript to Fetch Cell Value:
Code:
WebAutomation.LaunchEdge.LaunchEdge Url: $'''https://afd.calpoly.edu/web/sample-tables''' WindowState: WebAutomation.BrowserWindowState.Maximized ClearCache: False ClearCookies: False WaitForPageToLoadTimeout: 60 Timeout: 60 PiPUserDataFolderMode: WebAutomation.PiPUserDataFolderModeEnum.AutomaticProfile BrowserInstance=> Browser SET NumCol TO 1 LOOP LoopIndex FROM 2 TO 5 STEP 1 SET NumRow TO LoopIndex SET Xpath TO $'''//*[@id=\"content\"]/table[1]/tbody/tr[%NumRow%]/td[%NumCol%]''' WebAutomation.ExecuteJavascript BrowserInstance: Browser Javascript: $'''function ExecuteScript() { // Define the XPath const xpath = \'%Xpath%\'; // Use document.evaluate to find the element const result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); // Get the node from the result const cell = result.singleNodeValue; // Check if the cell is found and get its value if (cell) { const cellValue = cell.textContent.trim(); // Use trim to remove any surrounding whitespace alert(cellValue); } else { alert(\'Cell not found. Please check the XPath and ensure the element exists.\'); } }''' Result=> Result END
How to copy and paste the above code into your power automate desktop?
Thanks,Deenuji Loganathan 👩💻Automation Evangelist 🤖Follow me on LinkedIn 👥 -------------------------------------------------------------------------------------------------------------If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
Congratulations to our community stars!
Expanding mentorship, skilling, and AI innovation
These are the community rock stars!
Stay up to date on forum activity by subscribing.
David_MA 271 Super User 2026 Season 2
trice602 171 Super User 2026 Season 2
11manish 148 Super User 2026 Season 2