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 / Run JavaScript Functio...
Power Automate
Unanswered

Run JavaScript Function on web page

(0) ShareShare
ReportReport
Posted on by 30

Wanting flow to change value of drop down box on web page. Drop down value will be 'Strength' and Field 3 is referencing which drop down box.

 

Run action but value is not changing need assistance with syntax. Any help is appreciated!

 

 

rhawkins10701_0-1631650846294.png

 

I have the same question (0)
  • VJR Profile Picture
    7,635 on at

    Hi @rhawkins10701 

     

    Could you also please try with the other options like

     

    document.getElementById('Field3').value = 'Strength';
    document.getElementById('Field3').selectedIndex = 2;    //Starts from 0, if Strength is at the 3rd position

     

    Also right click on that element and Inspect the code for the dropdown.

    Also, some dropdown values are only triggered if the text is written via SendKeys




    -------------------------------------------
    Help fellow beings find relevant posts.
    Upvote to a supporting response.
    Mark as solution to an answer.

  • rhawkins10701 Profile Picture
    30 on at

    Thanks I attempted both syntax and still not triggering the dropdown value.  I am not familiar with SendKeys that you were referring to. How would I write text via SendKeys? 

     

    Thanks for your assistance!

  • VJR Profile Picture
    7,635 on at

    Hi @rhawkins10701 

     

    Sendkeys should be the last resort when nothing else works.

     

    You are using Power Automate Desktop, so curious to know why are you looking to inject javascript to change the dropdown value?

    You can spy that element and perform any of the UI Automation options that PAD gives.

    Set drop-down list value on web page:

    https://docs.microsoft.com/en-us/power-automate/desktop-flows/actions-reference/webautomation#setdropdownlistvaluebase

     

     

    This is how the dropdown on the webpage looks like

     

    VJR_0-1631851994184.png

     

    This is the html of the above webpage

    VJR_3-1631852223415.png

     

     

     

    Changing the car value using "Set drop-down list value on web page":

    VJR_1-1631852091436.png

     

     

    After running the process the dropdown value is changed

    VJR_2-1631852172030.png

     

     



    -------------------------------------------
    Help fellow beings find relevant posts.
    Upvote to a supporting response.
    Mark as solution to an answer.


  • rhawkins10701 Profile Picture
    30 on at

    Thanks for the assistance with the new action! I am still having issues and I am thinking it is because the web page is crystal reporting. Would this have an effect on the action? I added new UI element and selected the drop down value.

     

    rhawkins10701_0-1632153835651.png

     

    Also, prior to selecting the drop down value I have to click "click to select custom fields" in order to display the drop down values. I've attempted to use action Click Link on Web Page to display drop down values but wasn't working.

     

     

     

    rhawkins10701_2-1632153938808.png

     

     

    rhawkins10701_1-1632153879098.png

     

  • VJR Profile Picture
    7,635 on at

    Hi @rhawkins10701 

     

    Yes it is true that some webpages are not "spyable" due to the nature they are built.

     

    - Are you able to see the html of the select dropdown just like the way I showed you

    VJR_0-1632197486716.png

     

    - play with the selectors and see which one behaves better than the other.

    Keep ticking one or more combination of options

     

    VJR_1-1632197651765.png

     

     

    - I will anyways share with you the Sendkeys option too but do keep it as your last alternative

     

    • Click on that element
    • Use appropriate Wait time
    • After Sending the Down arrow it selected the second element in below screenshot
      • Here you can also send the Down arrow multiple times depending on where your 'Strength' value is in the list
      • Alternatively, you can also type the initial alphabet or the starting few characters like S (as in Strength). Take care about another word starting with the same character S).

    VJR_2-1632198156648.png

     

     

    - For reference Saab is the 2nd option in the list.

    VJR_3-1632198423177.png






    -------------------------------------------
    Help fellow beings find relevant posts.
    Upvote to a supporting response.
    Mark as solution to an answer.

     

  • maxpower45255 Profile Picture
    223 on at

    I'm piggy-backing on this if it's ok.

    I have a web page that returns an unknown number of invoice lines in an html table. I'd like to loop through them and read the values of certain fields if a checkbox next to each line (row) is checked. I'm experimenting with the "run javascript function in a webpage" action but it's not returning anything. I'm trying to find all the checkboxes with a certain CSS class, then hopefully loop through each. The action appears to take a few seconds and almost looks like it's hanging. Then it completes without errors. But my result still shows blank.  

     

    function ExecuteScript() {var collection = document.getElementsByClassName("invoiced-class"); return collection.length;}

     

    thanks!

  • momlo Profile Picture
    1,527 Super User 2024 Season 1 on at

    Hi @maxpower45255 

     

    1. I always test in browser console if your JS works before using in PAD - this gives me clear information there is a issue is with JS code or on PAD side.

     

    2. I find that with some pages, I need ti "click" any element on the page before executing the JS -making the window in focus does not do the trick, you need to click the actual element for page to accept the JS.

     

    So first test if browser console returns anything for you when you use your code, and only then (if it does) come back to PAD.

  • maxpower45255 Profile Picture
    223 on at

    @momlo Thanks for the tips. I figured out the primary issue is the browser type. The javascript action seems to only work with Microsoft Edge. I am also unable to explain the intermittent success I'm having with this javascript action. Yesterday, I was able to get it working by starting the developer console. Then my javascript action seemed to work just fine, even after I closed it. Today, without making any changes to my flow, the same logic won't work. 

    One thing I noticed is I was getting a message in Edge when the javascript action triggers that says "Edge is being debugged" or something of that sort. Today, I'm not getting that at all. 

    Any help with this behavior would be appreciated. This is very annoying, and I've been wasting my time doing trial and error to figure out this issue, but to no avail. 

     

  • rajanrajamany1 Profile Picture
    4 on at

    @maxpower45255 Whether you found any solution? I'm facing similar issue, Run JavaScript Function on web page is not working.

  • maxpower45255 Profile Picture
    223 on at

    @rajanrajamany1 I have not. Unfortunately I haven't had to work on this again. My priorities shifted. But I'd love to know if someone figures this out. Hopefully MSFT is monitoring these threads and might comment. Good luck and please update this thread if you ever find a solution. 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 801

#2
Valantis Profile Picture

Valantis 602

#3
Haque Profile Picture

Haque 581

Last 30 days Overall leaderboard