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 functi...
Power Automate
Answered

'Run javascript function' get URL

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi Community

I am trying to fetch a link stored in an element on a web page and the plain text for that element.
The reason for this is the UI 'Click link on web page' doesn't work. The PAD UI spy, for some unknown reason, can't locate these elements. I even tried manually adding the path in the selector, but nothing worked.

I can easily inspect the element and find JS path, XPath, selector etc.
However I am unfortunately not capable enough to return the values properly in the 'Run javascript function' action and thus only get the dissappointing 'undefined' in results.

Any kind of help would be appreciated.


My function 😢:

function GetURL() {
    var URL = document.querySelector('#brandBand_2 > div > div > div > div > div.centerRegion > div > div.listViewContainer > lightning-datatable > div.dt-outer-container > div > div > table > tbody > tr:nth-child(1) > th > lightning-primitive-cell-factory > span > div > lightning-formatted-url > a').textContent;
    return URL;
}


Selector: #brandBand_2 > div > div > div > div > div.centerRegion > div > div.listViewContainer > lightning-datatable > div.dt-outer-container > div > div > table > tbody > tr:nth-child(1) > th > lightning-primitive-cell-factory > span > div > lightning-formatted-url > a

JS Path: document.querySelector("#brandBand_2 > div > div > div > div > div.centerRegion > div > div.listViewContainer > lightning-datatable > div.dt-outer-container > div > div > table > tbody > tr:nth-child(1) > th > lightning-primitive-cell-factory > span > div > lightning-formatted-url > a")

 

XPath: //*[@id="brandBand_2"]/div/div/div/div/div[2]/div/div[2]/lightning-datatable/div[2]/div/div/table/tbody/tr[1]/th/lightning-primitive-cell-factory/span/div/lightning-formatted-url/a


Thanks in advance!

  • VJR Profile Picture
    7,635 on at

    Hi @Anonymous 

    Is this a publicly available website that can be taken a look at?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    No unfortunately it is a service hosted by Salesforce.

    I haven't encountered any cases like this so it seems pretty unique to Salesforce websites.
    This may be a shot in the dark but the website sorta has a window inside the webpage (it could just be a layout).
    I initially thought it was an iFrame issue, but there are no iFrames on the site.

    Not much to go on, I know.

  • VJR Profile Picture
    7,635 on at

    Check if you are able to do some kind of a back-door entry like getting some other outer html text and then using string functions extract the url part.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I'll try and give it a shot.

    Do you have a code snippet and a public website where I can test it? I'm unsure whether what I'm doing in the 'Run JavaScript function on web page' is even correct 😛

    A nice day to you!

  • VJR Profile Picture
    7,635 on at

    Usually I use the w3schools editor for any html or javascript testing.

    But if your website is calling some external functions/scripts those might not be made available in w3schools but you can give it a try.

    https://www.w3schools.com/js/tryit.asp?filename=tryjs_myfirst

     

  • VJR Profile Picture
    7,635 on at

    can also try opening that website in Chrome and use its javascript console

    https://developer.chrome.com/docs/devtools/console/javascript/

     

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I have made a workaround the issue. I'll explain the issue and provide the solution in case anyone might stumble upon an issue like this.

    Apparently the Salesforce website has these unique html attributes called "lightning-datatable".
    NOTHING within these elements can be captured or accessed, either through the UI spy or javascript through the browser console (thx @VJR for the suggestion).
    As I only needed the name and link found in some of these elements my solution is simply to use 'Get details of web page' and then extract the full Web page source, then parse out the info I need with RegEx (I use .NET Regex Tester - Regex Storm for Regex testing).
    Not an elegant solution, but it works.

    If anyone finds a way to access the "lightning-datatable" elements, or any other custom elements, then please share your findings! I am very interested in finding a more robust solution using the html DOM/tree.

    Thank you to @VJR for the pointers.

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

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 432

#2
11manish Profile Picture

11manish 313 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 154

Last 30 days Overall leaderboard