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 / POWER AUTOMATE DESKTOP...
Power Automate
Unanswered

POWER AUTOMATE DESKTOPの「WebページでJavaScript関数を実行」アクションにおける文字列取得の値が[object Object]になる

(0) ShareShare
ReportReport
Posted on by 14

POWER AUTOMATE DESKTOP において、「Web ページで JavaScript 関数を実行アクション」(以下)を使い、Web ページの特定のセレクタを指定して、インナーテキストを取得した結果の値を外部 Excel ファイルに書き込むと、object Objectになります。
(「WebページでJavaScript関数を実行」アクションの実行が倒される「変数」が結果的に、[object Object]になっております。)なお、Webブラウザのコンソール上で叩かれますと
期待値通り、問題なくテキストは取得できます。

この問題を解決するために、JSON.stringify() メソッドやtoString() メソッドを使って、文字列に変換しようと試みましたが、結果は、引き続き[object Object]でしまし

教えていただければ幸いです。

■「WebページでJavaScript関数を実行」アクションに入れているスクリプトは以下になります。

関数Exec​​Script() {

return document.querySelector("#body > div.mainarea > table > tbody > tr:nth-child(15) > td > pre").innerText;

}

ExecuteScript();

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @Yasu176 - Hope you are doing well!!

     

    Typically, when executing JavaScript code, if it doesn't return a string or normal text, then it would return value as an object. 

     

    For instance:

    I attempted to retrieve some inner text from the Power Automate Desktop community page, and it functioned correctly. Please review the code below or copy and paste it into your system to observe its functionality.

    Deenuji_0-1708403648439.png

     

    Code:

    WebAutomation.LaunchChrome.LaunchChrome Url: $'''https://powerusers.microsoft.com/t5/Power-Automate-Desktop/bd-p/MPADesktop''' WindowState: WebAutomation.BrowserWindowState.Maximized ClearCache: False ClearCookies: False WaitForPageToLoadTimeout: 60 Timeout: 60 PiPUserDataFolderMode: WebAutomation.PiPUserDataFolderModeEnum.AutomaticProfile BrowserInstance=> Browser
    WebAutomation.ExecuteJavascript BrowserInstance: Browser Javascript: $'''function ExecuteScript() {
    var Titleheader= document.querySelector(\"#lia-body > div.lia-page > div.MinimumWidthContainer > div > div > div > div.lia-quilt.lia-quilt-forum-page.lia-quilt-layout-two-column-main-side.lia-top-quilt > div.common_pageTitle > h1 > span\").innerText;
    return Titleheader;

    }''' Result=> Result

     

    If you require further assistance, kindly provide screenshots of your code. This will enable us to offer more accurate.

     

    Thanks,

    Deenu

     
     
  • Yasu176 Profile Picture
    14 on at
    Hello Deenuji, I apologize for my delayed response. Thank you very much for your appropriate advice. As you mentioned, indeed, when I executed the code you provided, it returned the expected results. I am attempting to retrieve user-specific report comments (text strings) for a certain groupware product. I am using JavaScript to obtain UI elements through selector specification, and with a ForEach action, I extract comments for each user and write them to an Excel file. However, while I am able to retrieve other UI elements, I just cannot seem to get it right with the targeted element. (When executed in the browser console, it does return correct results.) I have tried using the JSON.stringify() method to extract the text and thought it might be dynamically generated elements, so I also experimented with MutationObserver and promises but to no avail; the results remained the same. I thought if it is an object Object, it should be possible to extract its contents. If there are any clever solutions or methods to retrieve this information, could you please share your insights? I look forward to your guidance. Thank you very much.
  • Yasu176 Profile Picture
    14 on at

    Dear Deenuji,
    Please consider this a postscript.
    I am sending you a screenshot of the flow designer to give you a visual of the flow.
    The platform has been substituted with our Microsoft Power Automate Community forum for the purpose of this illustration. The process involves using a name of a "Kudoed Author" from an Excel list to search on the search screen. Upon finding the result, the anchor link is clicked to capture the title of the subsequent page. The captured string is then recorded back into Excel.
    While this produces the expected results on the current platform, the process does not work properly on a different platform (a groupware service).
    Kind regards,

    PAD_Flow_ScreenShot.png

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @Yasu176 

     

    Did you include "innerText" after selecting the element in your JavaScript code as shown below?

    Deenuji_1-1708920943236.png

     

    I was able to extract data from the sample "groupware demo portal". If we omit mentioning innerText in our code, it will only return our data as an object.

    Deenuji_0-1708920901500.png

     

    Certainly! If you could share the JavaScript code, I'd be happy to take a look and assist you further. Feel free to omit any sensitive information before sharing it.

     

    Thanks,

    Deenu

  • Yasu176 Profile Picture
    14 on at

    Hello @Deenuji,
    Thank you for promptly checking on the matter.

    I have indeed implemented the innerText property, and I am able to retrieve the desired element (text string) via the web browser console.

    I have prepared a flow that can reproduce the "object Object" issue, so could you please check the attached materials at your convenience?

    The flow is recorded on the "PAD_flow" sheet of the Excel file, which you can copy and paste into the PAD flow designer. You may place the Excel file in any preferred location and specify the path accordingly.

    The flow retrieves the Top Kudoed Authors listed in column B of the external Excel list, and iterates through them using the ForEach action. Using the JavaScript `innerText` property, it obtains the title of each Kudoed Author page.

    The retrieved page titles are then written to column C of the external Excel.
    ・SudeepGhatakNZ
    ・SamLed
    ・Cfernandes


    I apologize for the inconvenience and appreciate your cooperation.

    Best regards,

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @Yasu176 
    Could you please share the flow which you created for forum use case? 

  • Yasu176 Profile Picture
    14 on at

    @Deenuji

    I apologize for the confusion in my previous explanation.
    In the comment that I replyed to the other day, I attached a file called list.xlsx, which contains a sheet named "PAD_flow." This sheet includes the flow code I created for the forum's use case.
    I will attach the list.xlsx file here again for your reference. Could you please check the "PAD_flow" sheet?
    If you copy all the code listed on the "PAD_flow" sheet and paste it into the Power Automate Desktop's flow designer(Workspace), I believe the flow should be constructed.
    I apologize for any inconvenience and appreciate your assistance.

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @Yasu176 

     

    I've made some slight modifications to your JavaScript, and I've included them here for your reference. It's working well for me.

     

    Updated Javascript:

     function ExecuteScript() {
    return document.querySelector("#lia-body > div.lia-page > center > div.MinimumWidthContainer > div > div > div > div.lia-quilt.lia-quilt-view-profile-page.lia-quilt-layout-two-column-main-side.lia-top-quilt.lia-user-viewing-other > div.common_pageTitle > h1 > span").textContent;
    }

     

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

    If I've resolved your query, please consider accepting it as the solution and giving it a thumbs up to help others find answers faster.

     

     

  • Yasu176 Profile Picture
    14 on at

    @Deenuji 

    Thank you for providing the modified code.
    I was able to confirm that it is possible to retrieve the text by switching from the innerText property to the textContent property.

    However, while trying to execute the same script on a different service where the issue is occurring, not on this forum, I received an 'object Object' instead of the text.
    I attempted to resolve the issue by changing the property from innerText to textContent, but it was unsuccessful.
    I will prepare so we can replicate the issue of receiving 'object Object' on the service where the problem is happening and consult with you once again.
    (I should have done this from the beginning... I apologize for the inconvenience caused.)

    Please continue to assist me going forward.
    I greatly appreciate your support.

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
11manish Profile Picture

11manish 231 Super User 2026 Season 2

#2
David_MA Profile Picture

David_MA 217 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 170

Last 30 days Overall leaderboard