Special_K has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I just installed WWW::Mechanize::PhantomJS and am trying to run the first sample program I found here:
http://search.cpan.org/~corion/WWW-Mechanize-PhantomJS-0.08/lib/WWW/Mechanize/PhantomJS.pm

Here is the actual code:


#!/usr/bin/perl -w use strict; use WWW::Mechanize::PhantomJS; my $mech = WWW::Mechanize::PhantomJS->new(); $mech->get('http://google.com'); $mech->eval_in_page('alert("Hello PhantomJS")'); my $png= $mech->content_as_png();

When I try to run it I get the following error:


./phantomjs_test.pl Can't exec "phantomjs": No such file or directory at /usr/lib/perl5/si +te_perl/5.14/WWW/Mechanize/PhantomJS.pm line 131. Couldn't launch [| phantomjs /usr/lib/perl5/site_perl/5.14/WWW/Mechani +ze/PhantomJS/ghostdriver/main.js --port=8910 --logLevel=OFF]: No such + file or directory / 0 at /usr/lib/perl5/site_perl/5.14/WWW/Mechanize +/PhantomJS.pm line 131.

FWIW, line 131 of PhantomJS.pm is as follows:


$options{ pid } = open my $fh, $cmd

and $cmd is:


my $cmd= "| $options{ launch_exe } $options{ launch_ghostdir } @{ $opt +ions{ launch_arg } }";

Does anyone know what the problem could be?

Replies are listed 'Best First'.
Re: WWW::Mechanize::PhantomJS - can't exec "phantomjs"
by NetWallah (Canon) on Sep 13, 2014 at 05:55 UTC
    The installation instructions for the perl module WWW::Mechanize::PhantomJS are rather cryptic, but they DO say:
    INSTALLING

    Install the PhantomJS executable

    So - you DO need to download and install it from the PhantomJS download page.

            "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams

      Thanks - I didn't read the page closely enough and assumed cpan would take care of all dependencies. NEW ISSUE: Rather than make a new post, I'll just add this one: After downloading phantomjs.exe and pointing to it in my test program above using this line:
      my $mech = WWW::Mechanize::PhantomJS->new(launch_exe => "/home/user1/p +hantomjs.exe");

      I now receive the following error when I try to run it:


      Can't open '/usr/lib/perl5/site_perl/5.14/WWW/Mechanize/PhantomJS/ghos +tdriver/main.js' Selenium server did not return proper status at (eval 82) line 61.

      Any ideas on this one? The main.js file referenced in the message does exist.

Re: WWW::Mechanize::PhantomJS - can't exec "phantomjs"
by Special_K (Pilgrim) on Sep 19, 2014 at 04:34 UTC
    After some digging, I found the solution. It turns out that while cygwin can call windows executables, the POSIX-style pathnames that cygwin uses (e.g. /home/user/hello.js) must first be converted to Windows-compatible paths (e.g. C:\cygdrive\cygwin64\home\user\hello.js) using the cygpath utility. Here is the actual code I had to use:

    my $mech = WWW::Mechanize::PhantomJS->new( launch_ghostdir => '"`cygpath -w /usr/lib/perl5/site_perl/5.14/WWW +/Mechanize/PhantomJS/ghostdriver/main.js`"', );


    I'm not sure why I need both double quotes and backticks to make it work, but that's what the example I found used, so I went with it. I decided to update this post because I hate searching and finding the exact issue I am having with no solution posted. Hopefully someone finds this information useful someday.