I'm using the action "Run JavaScript function on web page" for extracting day & month from a website. The problem is that the value returned by JS function (stored to DateVar as a power automate var) is treated as [object Object] by Power Automate.
Here is the JS code.
var dynamicSelector = '[data-test="qc-wrapper"]';
function extractAndConcatenateDate() {
// Find the elements by the dynamic selector
var cardElement = document.querySelector(dynamicSelector);
if (!cardElement) {
return 'Element not found';
}
// Find the elements by their class names or other attributes
var dateElement = cardElement.querySelector('.sc-ABC1 .sc-XYZ1');
var monthElement = cardElement.querySelector('.sc-ABC2 .sc-XYZ2');
// Extract the text content from the elements
var date = dateElement.textContent;
var month = monthElement.textContent;
// Return the concatenated date and month as a string
return date + month;
}
// Call the function and return the concatenated date and month as a string
return extractAndConcatenateDate();
I need to get the return value as text.
Since, it is returning as an Object, I thought and tried out the following approach.
- Create a new power automate variable using "Set variable" action: tempVar = "tempContent"
- In the JS fn, added a statement ( '%tempVar%' = date+month; ) hoping the text content will be updated to this power automate variable.
- Execute the "Run JavaScript function on web page".
- But tempVar still contains "tempContent" only.
So far, I can see only two options:-
- find a way to update tempVar inside JS function
- find a way to get text value from the returned [object Object]
I also tried using JSON.stringify while returning but still no luck!
Please provide your suggestions on this problem using Power Automate Desktop Flow.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/RCn6s3Q
Comments
Post a Comment