Skip to content Skip to sidebar Skip to footer

Using Angularjs Function In Phantomjs

I searched on the net and I found nothing. I have a script angularJS which appear or disappear element from my html page. I use a phantomJS script to access to the html page and do

Solution 1:

I finally found. A script PhantomJS use javascript so we just have to call angularJS element like in javascript:

This is angular.element($("#someThing")).scope(); to get the scope.

So we can have this example of phantomJS :

page.open('http://www.google.com', function (status) {
    if ('success' !== status) {
        console.log("Error");
    } else {
        page.evaluate(function() {          
            angular.element($("#someThing")).scope().aFunctionInTheScope();
            var scope = angular.element($("#myDiv")).scope();
            var width = scope.getWidth();
        });
        phantom.exit();
    }
});

with an angularJS code like this :

$scope.getWidth = function() {
     return1600;
}

and an html page like this :

<div id="myDiv">
    blabla
</div>

Post a Comment for "Using Angularjs Function In Phantomjs"