executeScript returning undefined when

Hi,
I am trying to extract emails and phone number (using extractScript) from a HTML part of the web page and for some reason it always return undefined. But when I use that same JS script in the console it works perfectly.
What could cause that?

Here are the two scripts I am using:

function findEmailAddresses(xPathHTML) {
  var emailsSeparator = ", ";
  var emailAddress = "<none>";
  var emailsArray = xPathHTML.match(/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/);
  if (emailsArray) {
    emailAddress = "";
    for (var i = 0; i < emailsArray.length; i++) {
      if (i != 0) { emailAddress += emailsSeparator; }
      emailAddress += emailsArray[i];
    }
  }
  return emailAddress;
}
findEmailAddresses(document.evaluate('//*[@id="m_wizard_form_step_3"]/div[@class="inbox_container"]/div/div[contains(@class, "inbox-middle-pan")]/div[@class="inbox-connection"]/div[@class="inbox-body"]/div[contains(@class, "m-messenger")]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerHTML);

And

function findEmailAddresses(xPathHTML) {
  var emailsSeparator = ", ";
  var emailAddress = "<none>";
  var emailsArray = xPathHTML.match(/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/);
  if (emailsArray) {
    emailAddress = "";
    for (var i = 0; i < emailsArray.length; i++) {
      if (i != 0) { emailAddress += emailsSeparator; }
      emailAddress += emailsArray[i];
    }
  }
  return emailAddress;
}
findEmailAddresses(document.evaluate('//*[@id="m_wizard_form_step_3"]/div[@class="inbox_container"]/div/div[contains(@class, "inbox-middle-pan")]/div[@class="inbox-connection"]/div[@class="inbox-body"]/div[contains(@class, "m-messenger")]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerHTML);

Thanks in advance!

Use storetext to extract data from html page no need your long code.

In what language is written your code ?
It does not seem to me ui vision, use the commands of ui vision to do this work.

That’s JavaScript. And the reason why I don’t use storeText or sourceExtract is because, it’s from a conversation platform (e.g.: Messenger) and I am looping in all conversation (so I need to get the HTML of that specific conversation NOT the whole page otherwise it would get other infos), and then in each conversation look if there’s a phone number or and email.

This is a support forum for ui vision rpa I don’t think you’ll find support for javascript.

I recommend you write on stackoverflow.com for your request that is not related to ui vision rpa.

Your work can be do with 3 lines of code of ui vision there is not any reason to use your long macro code, with storetext and split you can cut text and save prefered part.

I regulary store data from site without any problem with ui vision command.

I am not looking for JavaScript support, as the script is working. It’s the return value that is wrong in UI.Vision. It should return the email as it does when I test the script on the browser console, but instead it returns undefined in UI.Vision.

I’m new with UI.Vision… So, how would you do it?
You would storeText of an HTML section, then do a regex of it to extract the value of this specific text?

If you can post url page html i try to find a solution

It’s in a private platform where you need to login to access it. If you can guide me on how it’s possible to do a sourceExtract of a specific part of the HTML of the page (not the whole page) that would be helpful. Or how you would do it with StoreText and Split, that would also be helpful. Thanks

I suggest you to use an external grabber software.

For social media there are grabber that work better of a macro.code

Isn’t what UI.Vision RPA does?

I have seen on the internet software to save data from web pages that in a few seconds extract thousands of data quickly, ui vision is a great software but limited of the browser and it’s slow for these jobs.

With ui vision you can extract little data and you will have to take a long time (days or weeks) to create a good macro and can always crash.

Better a sofware that can extract thousands of data in seconds (customer grabber).

Just to clarify, the goal is not to extract massive data, the goal is only to look in each conversation, check if there’s a phone or an email in the conversation, then if there’s none to click on a specific button to launch a follow up sequence. And then once this is done, go to the next conversation, and etc.

We wait for other users to respond and provide a fix for your javascript code.

I do not understand how it works so I do not know how to help you.

I’ve never used a javascript code so long and complex in ui vision.

I not being able to see the page you have to work on I can not even recommend an alternative solution, you need to be able to see the pages to create good macro codes.