Sunday 12 March 2017

page.getElementsByClassName with phantom js node

I'm trying to open a URL and click a button with phatom-node but I'm unable to use getElementsByClassName with it.

This is the message I'm receiving.

(node:10960) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: _page.getElementsByClassName is not a function

This is my code:

phantom.create([])
        .then( instance => {
            console.log('CREATEPAGE');
            return instance.createPage();
        })
        .then( page => {
             console.log('PAGE');
            _page = page;
            return page.open(`url_here`);         
        })
        .then( status => {
            console.log('STATUS');
            console.log(status);
            return _page.getElementsByClassName("icon btn-icon icon-send send-container");
        })
        .then(function(input){
            console.log('CLICK');
            return input[0].click();

        });

How can I solve this?



via Filipe Ferminiano

No comments:

Post a Comment