Hey everyone,
I just ran with the same issue. According to PAD docs, the 'Run JavaScript function on webpage' will return a string (Text value) necessarily. Source: https://learn.microsoft.com/en-us/power-automate/desktop-flows/actions-reference/webautomation

You can transform JSON objects into strings (and, with this, allow PAD to return it form this action) by using this code: JSON.Stringfy([your_object])
In my case, I was trying to return some HTML elements caught through document.getElementById(), which returns an object (but not a JSON one). The workaround that I found was to get the parent element and use the 'innerHTML' property to access a string of the whole HTML code inside it.
For example, if I want to return the 'target div' below as string, I would need to access its 'parent div':
<div id="parent">
<div id="target">
<p><span>123</span > text text <i>abc</i></p>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
</div>
To achieve it, we can use in JavaScript document.getElementById('target').innerHTML, which will return everything inside the div#parent (basically the div#target and children) as string.
Also, you can replicate this same logic for querySelector, or any other JavaScript methods to manipulate the DOM.
Let me know if it works for you or if you need any additional help!
-------------------------------------------------------------------------
If this is the answer for your question, please mark the post as Solved.
If this answer helps you in any way, please give it a like.
http://digitalmill.net/