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
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!