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 / Getting button to clic...
Power Automate
Unanswered

Getting button to click using javascript

(0) ShareShare
ReportReport
Posted on by 124

I have a web app that I want to click a file selector button on but it doesnt work - or rather I can get it to work but only if I click on the pane that the button is in before PAD tries to call the click event/function.

 

function ExecuteScript()
{
document.window.focus(); getElementById('FileSelector').click();
}

 

the above it what Im trying but as I say, it doesnt work unless I click in the correct section - Ive tried using the Hover over UI element and then sending a click but that doesnt work either, I suspect as its not finding the element to click. Can anybody help?  This is driving me nuts!

Craigja_0-1692961323164.png

 

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

    Why are you using the .window.focus() method in your function? Are you using the Run JavaScript action under the Scripting actions group? I would suggest using the Run JavaScript function on web page action under the Browser automation actions group. When you provide the browser instance that you want to execute the function on, you will not need to focus a window.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • Craigja Profile Picture
    124 on at

    I am using the 'Run JavaScript function on web page' and providing the browser instance - a colleague said adding the window.focus() method might help

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    The way I see it is that all you need is this:

    function ExecuteScript()
    {
    document.getElementById('FileSelector').click();
    }

    Alternatively, since these file selector buttons are actually part of the browser UI and not as much the web UI, you can use the Press button in window or Click UI element in window actions under the UI automation actions group. Those usually work fine with these buttons.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • Craigja Profile Picture
    124 on at

    That doesnt work - thats what I tried first and only works if I manually click into the browser at the right hand side of the page where the button is.  I did try also the press button and click UI elements but these dont work either, I get an error that it cant find the button or element

  • Craigja Profile Picture
    124 on at

    Just tried again - if I use the Click UI element in window tool I get an error 'click failed (failed to get window)'

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    You might need to modify the selector there. Especially the parent window selector. For browser windows, it will contain the page title for when you captured it. If the page title can change, so will the title used in the selector. So, you need to remove the name parameter:

    Agnius_0-1692972515888.png

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • Craigja Profile Picture
    124 on at

    Craigja_0-1692974874493.png

    Thats how it looks - I dont have the window name

     

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    This is the selector when captured via Browser automation actions. When you capture it via UI automation actions, the selector will be different, and will have a parent window.

    It will never work if you use the same element in UI automation actions. If you try using UI automation actions, you must recapture the element to generate a proper selector.

    -------------------------------------------------------------------------

    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

     

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • Craigja Profile Picture
    124 on at

    Ah!  I didnt know that, thanks for the info

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    Does that work for you?

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 252 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 169

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard