web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Save Selector value in...
Power Automate
Answered

Save Selector value in a variable

(0) ShareShare
ReportReport
Posted on by 1,091 Super User 2024 Season 2

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!

I have the same question (0)
  • VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    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.

     

    VishnuReddy1997_0-1719570484541.png

     


    (Note:- if you got your solution you can mark as solution and gives kudos)


    Thanks & Regards

    Vishnu Reddy

  • TYL Profile Picture
    1,091 Super User 2024 Season 2 on at

    @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? 

  • VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    Hi @Tjan ,

     

    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_0-1719571483151.png

    VishnuReddy1997_1-1719571500607.png

     

    (Note:- if you got your solution you can mark as solution and gives kudos)


    Thanks & Regards

    Vishnu Reddy

  • TYL Profile Picture
    1,091 Super User 2024 Season 2 on at

    @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? 

  • VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    Hi @Tjan ,

     

    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_0-1719241432598.png

     

    (Note:- if you got your solution you can mark as solution and gives kudos)


    Thanks & Regards

    Vishnu Reddy

  • TYL Profile Picture
    1,091 Super User 2024 Season 2 on at

    @VishnuReddy1997  Here 'button[id="hdrSrch"]' is hardcoded right? Or is it a reference to an actual selector in your flow?

  • VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    Hi @Tjan ,

     

    Its a actual selector. Its a selector for clicking search bar in different website.

     

    Regards,

    Vishnu Reddy

  • NathanAlvares24 Profile Picture
    1,714 Moderator on at

    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?

  • TYL Profile Picture
    1,091 Super User 2024 Season 2 on at

    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.

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @Tjan 

     

    Please follow the below approach:

     

    • Launch Microsoft Edge Browser:

    • Set Initial Column Number:

      • Initialize the column number (NumCol) to 1.
    • Loop Through Table Rows:

      • Create a loop to iterate from the 2nd row to the 5th row of the table.
      • Set the current row number (NumRow) to the loop index value.
    • Construct the XPath for Each Cell:

      • Construct the XPath for the cell in the specified row and column.
      • The XPath format is: //*[@id="content"]/table[1]/tbody/tr[%NumRow%]/td[%NumCol%]
    • Execute JavaScript to Fetch Cell Value:

     

     

    Deenuji_0-1719588223502.png

     

    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?

    Deenuji_1-1719588276087.gif

     


    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.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 271 Super User 2026 Season 2

#2
trice602 Profile Picture

trice602 171 Super User 2026 Season 2

#3
11manish Profile Picture

11manish 148 Super User 2026 Season 2

Last 30 days Overall leaderboard