-1

Possible Duplicate:
Can't create an instance of WWW:Mechanize::Firefox

I have the following code, taken from the documenation of WWW::Mechanize::Firefox.

#!/usr/bin/perl

use WWW::Mechanize::Firefox;
my $mech = WWW::Mechanize::Firefox->new();
$mech->get('http://google.com');

$mech->eval_in_page('alert("Hello Firefox")');
my $png = $mech->content_as_png();

and I get this error message:

Failed to connect to , problem connecting to "localhost", port 4242: No connection could be made because the target machine actively refused it. at C:/strawberry/perl/site/lib/MozRepl/Client.pm line 144
Community
  • 1
  • 1
Grigor
  • 4,139
  • 10
  • 41
  • 79
  • try it with removing `::Firefox` from both lines and removing `eval` line. To use `eval` use `WWW::Scripter` library - see http://search.cpan.org/~sprout/WWW-Scripter-0.029/lib/WWW/Scripter.pod. Also don't expect *http://google.com* to return you a png as output... – Ωmega Jun 30 '12 at 18:37
  • @Daxim stop saying that last sentence over and over again. Wow. – Grigor Jun 30 '12 at 18:43
  • @Daxim followed your comment, it is enabled but still same error – Grigor Jun 30 '12 at 18:48

1 Answers1

2

Note: if you want a picture that is embedded in a web page then you should establish the URL of the image and download it directly. The content_as_png method will return a screenshot of the Firefox window.

Be absolutely certain that MozRepl is started and running on Firefox on your machine. Check this by going to Tools/MozRepl on Firefox and make sure that the first option is now Stop.

Once you know MozReply is running, open a command window and enter

telnet 127.0.0.1 4242

when MozRepl should reply with something like

Welcome to MozRepl.

and a few lines of advice. (If you are running on a Windows system then you can open a command prompt window by pressing the Windows key and entering cmd.)

Then you can finally make certain your connection is working by entering

repl.whereAmI()

(be careful of the capitalisation). And MozRepl will respond with

[object ChromeWindow] - Document title: "perl - WWW::Mechanize::Firefox doesn't want to work properly - Stack Overflow - Mozilla Firefox"

or similar.

If any of these steps don't work then come back here with your findings.

Borodin
  • 126,100
  • 9
  • 70
  • 144