0

I want to do the following:

  1. Go to a website
  2. Click on a button => a javascript function will change parts of the html
  3. Fetch some contents of the newly changed html

All these automatically

I tried several tools provided for nodejs including node-cralwer and PhantomJS

Currently, I have this code running in PhantomJS

page.open('https://www.thegioididong.com/dtdd/iphone-x-256gb', function (status) {
    console.log("Status: " + status);

    var a = page.evaluate(function () {

        document.getElementsByClassName("viewparameterfull")[0].click()

        console.log(document.getElementsByClassName('parameterfull')[0].textContent)
        return document.getElementsByClassName('parameterfull')[0].textContent
    })
    phantom.exit();
})

and the output was

Status: success
ReferenceError: Can't find variable: getFullSpec

Using Chrome Debugger, I can see that getFullSpec is a function that:

  • Is fired when the button selected in the code is clicked

  • Can be found on another js file that is downloaded when the page loads.

My questions are:

  • When PhantomJS opens a link with page.open(), does it load every file (js, css...) like the browser does?

  • If it does, how can I use PhantomJS to run that getFullSpec (which is contained in another js file)?

1 Answer 1

1
  1. Yes.
  2. Js in eveluate method will be executed in page, and there is an error in onclick listener.

You can open a page, open devtools, search for code in js sources.

Sign up to request clarification or add additional context in comments.

6 Comments

thanks for fast response! So you mean I can use PhantomJS to do this but I have error in my code? Can you tell me how to fix it?
It is error in page js file. I don't know how to fix, maybe getFullSpec is not initialized yet. So try to set delay before clicking.
Sorry I don't know if I get you right. If you mean the source's javascript has an error, I think that's not the case cause it works when I loaded it in Chrome.
Then you are doing a click before js.file which contains getFullSpec() is loaded. I don't know full phantom api, but try to eveluate you script, when all page js are loaded. Here is similar issue stackoverflow.com/questions/11340038/….
We came to proper solution in this post, so seems it must be the answer. I can edit it, but seems it is not needed.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.