samedi 29 décembre 2018

What is preventing a parent's children from being discovered by my code?

Currently writing a Greasemonkey script that automates. The automation starts off with first collecting elements in HTML that match a criterion. These are tags. Within a simple for loop, it will perform an automated click on each link, after which it will click on another link. After that, it will then enter some text before submitting the text for server processing. The for loop repeats the sequence until the list is exhausted. I have figured out how to build the collection of the desired elements, but for some reason, the code is not able to access some child nodes, returning results like 'null' and 'undefined'. The problem occurs in this section of code:

$(".indeed-apply-button").html();

This class is part of the tag.

So I have tried to access the child nodes with querySelector(), which returns undefined. I tried using $(); selector. It will return [object Object]. With .html() appended, it will return undefined.

The tag that I wish to extract from the document is confined within several parent tags. Somewhere in the code within the series of those tags exists a point where my code either refuses or is unable to access the child nodes.

To help further clarify this, this is done on indeed.com. This code runs after a job search. It will select each job in the list then click the apply button. For example, https://www.indeed.com/q-programmer-l-maine-jobs.html

What could cause some elements to not be able to be retrieved, would be a more general question.

$(document).ready(function(){

var jobList = document.querySelectorAll("a[data-tn-element='jobTitle']");

  function clickThenApply (jobNumber) {
    var jobTitle = $(jobList[jobNumber]).attr("title"); //job name
    var jobLink = $(jobList[jobNumber]).attr("href"); //job link
    jobList[jobNumber].click();
    var apply = $(".indeed-apply-button").html();
    console.log("Job title: " + jobTitle);
    console.log("Job link: " + jobLink);
    console.log("success? " + apply);
    return true;
    }

  for (var i = 0; i < jobList.length; i++) {
  var tog = clickThenApply(i);
  }

});

The problem occurs in this section of code:

$(".indeed-apply-button").html();

This class is part of the tag. It should return HTML code, but it instead returns undefined.

I have tried:

document.querySelector("a.indeed-apply-button");

It returns null/undefined.

If you could provide any insight into this, I would appreciate it!




Aucun commentaire:

Enregistrer un commentaire