Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

82
Views
page.evaluate returns null document

Below is the phantomjs code

page.open('https://onli**************uickpay.html', function (status) {
    if (status !== 'success') {
        console.log('Unable to access network')
    } else {
        console.log('internet is working');
        var ua = page.evaluate(function (loanID) {
            var loanIDSplit = loanID.split('/');
            document.getElementById("txtBranchCode").value = loanIDSplit[0];
            document.getElementById("txtType").value = loanIDSplit[1];
            document.getElementById("txtLoanNumber").value = loanIDSplit[2];
            document.getElementById("btnLoanNoSearch").click();
        }, loanID);

    console.log(util.inspect(document, false, null));
    setTimeout(function () {
        var html = page.evaluate(function () {
            var table = document.getElementById('tblQpLoanNo');
            table.getElementsByClassName('odd')[0].click();
            document.getElementById("LoNoPayButton").click();
            return document;
        });
        page.render('/home/ubuntu/github.png');
        console.log('is the value of document'+html);
    }, 3000);

    setTimeout( function (){
      var release_amount = page.evaluate(function () {
      var table = document.getElementById('tblQpPayment');
      var row = table.getElementsByClassName('odd')[0];
      var payableAmount = row.getElementsByTagName('td')[3].textContent;
      return payableAmount;
  });

     console.log("release amount value is "+release_amount);
     // system.stdout.write("$" + releaseAmount);
     // system.stdout.write("$" + loanID);
     phantom.exit();
}, 10000);
}

when the above peace of code runs, the html value that is logged is showing up null

It works perfectly with phantomjs in macosx but when I have deployed it to ubuntu server it is not working. I made sure I am using phantomjs that supports linux

The first page.evaluate works fine, where as the next page.evaluate after 3 seconds timeout is not working, I have wasted enough time on debugging and finally asking over here, If some one had same issue or if some information is missing please feel to ask me.

what can be the reasons for document being null, that means there is some problem in evaluating the html page

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You cannot return document from page.evaluate because, according to the docs

Closures, functions, DOM nodes, etc. will not work!

If you want to get the whole html of the page, try a built-in page.content variable:

console.log(page.content);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!