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
Answered

Run JavaScript function on web page not executing

(0) ShareShare
ReportReport
Posted on by 13

Hi everyone,

 

I've been trying to execute .click() on an web element using the code supplied in this documentation: https://learn.microsoft.com/en-us/power-automate/desktop-flows/how-to/populate-text-fields-click-links-javascript 

 

function ExecuteScript()
{
document.querySelectorAll('CSS-Selector')[0].click();
}

 

I've tested the selector and .click() function in the console successfully, but I can't get it to execute from the power automate action. Is this feature currently broken? I would appreciate any feedback. Thank you!

I have the same question (0)
  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    Are you literally passing the value 'CSS-Selector' in there, or did you not want to share the actual selector you're using?

  • happybara Profile Picture
    13 on at

    Haha nah that's not the selector I'm using, I just copy pasted the example listed in the PAD documentation I listed, I can see how that was confusing though. 

     

    The actual selector I'm using I grabbed using inspect element, and when I use .click() on it in the console it works great, so I think the selector shouldn't be the issue. 

  • happybara Profile Picture
    13 on at

    this is the selector I've been using, if you are curious: document.querySelector("#divToolbar > div:nth-child(1) > table > tbody > tr > td.icon-button.menu-button")

  • Deenuji_Loganathan_ Profile Picture
    6,250 Moderator on at

    @happybara 

    It's functioning perfectly on my system. Please take a look at the code below to see how it operates for me.

     

    I attempted to click the reply button on this webpage and then copied the JavaScript path from the browser's inspect tool. After pasting the code into the PAD JavaScript action, it worked flawlessly for me.

     

    Flow screenshot:

     

    Deenuji_0-1710697486057.png

     

    Code:

    WebAutomation.LaunchChrome.LaunchChrome Url: $fx'https://powerusers.microsoft.com/t5/Power-Automate-Desktop/Run-JavaScript-function-on-web-page-not-executing/m-p/2660450#M38273' WindowState: WebAutomation.BrowserWindowState.Maximized ClearCache: False ClearCookies: False WaitForPageToLoadTimeout: $fx'=60' Timeout: $fx'=60' PiPUserDataFolderMode: WebAutomation.PiPUserDataFolderModeEnum.AutomaticProfile BrowserInstance=> Browser
    WebAutomation.ExecuteJavascript BrowserInstance: $fx'=Browser' Javascript: $fx'function ExecuteScript() { 
    document.querySelector("#link_27").click();
    }' Result=> Result

     


    Thanks,
    Deenuji Loganathan
    🤖 Automation Evangelist
    Deenuji - 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 🌟

  • happybara Profile Picture
    13 on at

    Hi @Deenuji, Thank you for looking into this. Unfortunately when I tried making the same flow as you did, it did not work for me. What PAD version are you using? I have upgraded to the most recent one, I'm thinking that may be causing my issues. 

    happybara_0-1710698866348.png

     

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,250 Moderator on at

    @happybara 
    I am using latest version 2.42 with power fx enabled flow. Pls try to create one flow with power fx enabled and copy/paste my above code and see if it resolves your issue

     

    In case if you want to try this functionality with stable version, you can try 2.39 version also. Link to download below..

     

    link to download 2.39 - Setup.Microsoft.PowerAutomate.zip 


    Thanks,
    Deenuji Loganathan
    🤖Automation Evangelist
    Deenuji - 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 🌟

  • happybara Profile Picture
    13 on at

    Oh my lord enabling power FX worked. I am sending you the biggest internet hug right now. I was stuck on this for days and was ready to give up on PAD. Thank you so much for the help Deenuji 🙂

  • Deenuji_Loganathan_ Profile Picture
    6,250 Moderator on at

    @happybara 

    Beginning my day with your virtual hug fills me with emotions, making it an amazing day indeed.

     

    Also, since my code contains FX enabled features, I recommend creating your flow with Power FX enabled to try out my suggestions and it worked 😍. Wishing you a happy automation journey with power automate desktop!

     


    Thanks,
    Deenuji Loganathan
    🤖 Automation Evangelist
    Deenuji - 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 🌟 If you'd like to appreciate me, please write a LinkedIn recommendation🙏

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 1,027

#2
Valantis Profile Picture

Valantis 809

#3
Haque Profile Picture

Haque 645

Last 30 days Overall leaderboard