Javascript Function - Return Response

I am trying to select the job posting titles and the href for the job postings. Then return response. Can you tell me what I am doing wrong here?

Website: NemoursCareerSite

Here is my last attempt:

function ExecuteScript() {
    let response = '';
    document.querySelectorAll('h2[data-bind="text: job.title"]').forEach((element, i) => {
      response += element.innerHTML + '\\t' + location.host + element.getAttribute('href') + '\\n';
    });
    return response;
  }
1 Like

What do you expect it to do?

If you are trying to tab and make a new line its just one slash: \t, \n

I am using a Javascript function on this webpage in a Microsoft Power Automate Desktop workflow. I was using this Javascript function to return the values of all these elements as a variable. Does that make sense?

What do you mean by values?

It does return all the inner html of all the nodes as a single string, is this not what you want?

Ah! I am sorry. You are right! It is correct. I accidentally had an incorrect format when pasting it in Microsoft Power Automate Desktop. Thank you!

1 Like

No problem, good coding!

Ok, so I was wrong. I was able to get the job title, but the href is incorrect. It pulls part of it and then says ‘null’.
I think I need to do 2 separate loops since these are not nested under the same element. I tried to merge them into 1 loop which may not be correct. Can you help me get the ‘href’ of the job posting as well?

This would get you a matrix where each array contains the <a/> and sibling <h2/>

function ExecuteScript() {    
    const links = document.querySelectorAll('li.job-tile a');
    const allH2 = document.querySelectorAll('h2[data-bind="text: job.title"]');
    const nodes = [];
    links.forEach((node, i) => nodes.push([node, allH2[i]]))
    return nodes;
  }