1

I'm completely new in PhantomJS and JavaScript and I'm starting learn something. I have this code:

var page = require("webpage").create()
var system = require("system"); 

page.onConsoleMessage = function(msg) 
{
        system.stderr.writeLine("console: " + msg);
};

page.open("https://www.mywebsite.com/",function(status)
{   
    if(status !== "success")
        {
            console.log("status !== \"success1\"")
            phantom.exit(1); // 1 = error exit code
    }

        var aa = page.evaluate(function(s) 
        {
            var sbb = document.getElementsByClassName("name")[0].children[0].children[1].children[0].children[1].children[0];

            sbb.click();

            return sbb;
        })

        console.log(aa)
        phantom.exit() // 0 = success exit code
});

In this way I am able to click on the element represented by the variable sbb. The output is

https://www.mywebsite.com/sbb

Now I want to recover an element inside this new page. I read that there is a problem of scope, but I thought that putting the new url in the return statement I could create a new evaluate function in order to access to the new page, but it is not so. Someone can give me a hint, please? Thanks a lot!

  • Can you clarify what the problem is? You want to open another page after evaluating the current one? – devius Mar 08 '18 at 16:33
  • `sbb.click();` followed by `return sbb;` - So you want to return the function reference to be printed to the console? – Nope Mar 08 '18 at 16:36
  • Please don't post links to your external sites. They most likely change over time or are dead-links in the near future and are no longer relevant to the question, making it useless for future users. - Include all relevant data inside the question directly, – Nope Mar 08 '18 at 16:37
  • @devius: I want to do a document.getElementsByClassName("otherName") in the new url, I want to be able to navigate in this new page. Sorry for the link, it not a real website, it was just a general example to not put a real website – user2907822 Mar 08 '18 at 17:01

0 Answers0