Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Problem using MozRepl and MozRepl::RemoteObject

by cf006 (Initiate)
on Nov 04, 2013 at 14:16 UTC ( #1061128=perlquestion: print w/ replies, xml ) Need Help??
cf006 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am new on this forum and first I would like to greet all the perlmonks.
My question is about the use of MozRepl module.
I have installed the add-on MozRepl for firefox and started it. The MozRepl perl module is of course installed.
I would like to automate some tasks with firefox, and think it is a good idea to use MozRepl.
For simple examples, it seems to work good.
For instence, in the following code, after the connection to mozrepl, I load a new html page and execute some instructions, to get all the links in the page. Then, still using commands that I could use in a console mode, I create the function all_a without parameter to display all the links founded before using the javascript function 'alert', and finaly click on the fourth link of the list.

#!/usr/bin/perl -w use strict; use warnings; use MozRepl; my $repl = MozRepl->new; $repl->setup; $repl->execute('content.document.location.href="http://www.google.fr/f +irefox"'); $repl->execute('repl.whereAmI()'); $repl->execute('repl.enter(content)'); $repl->execute('a = document.getElementsByTagName("a")'); $repl->execute('function all_a() {var all=""; for(var i=0;i<a.length;i +++) {all += i + ":" +a[i] + "\n"; } alert(all); };'); $repl->execute('all_a()'); $repl->execute('a[3].click()'); <>;

That's good but not satisfying, especially if I want to explore deeper data contained in the DOM, and that's why I thought to use MozRepl::RemoteObject, in addition to MozRepl. So, after reading the manual of MozRepl::RemoteObject, I proceed as follow, to connect the two modules :

#!/usr/bin/perl -w use strict; use warnings; use MozRepl; use MozRepl::RemoteObject; my $repl = MozRepl->new; $repl->setup({ log => [qw/ error info /], plugins => { plugins => [qw[ JSON2 ]] }, }); my $bridge = MozRepl::RemoteObject->install_bridge(repl => $repl); <>;

But, at this stage, I have the following error message :
"command timed-out at C:/Perl/site/lib/MozRepl/Client.pm line 186"
and the script dies.
I reproduced this result with Windows XP and with Linux Debian Squeeze.
I try to make a script working for now several weeks, and I didn't manage to automate tasks with firefox. I wonder if I should not give up.
Is it the right way to do what I want ?
Thank's for any information that could help me.
cf006

Comment on Problem using MozRepl and MozRepl::RemoteObject
Select or Download Code
Re: Problem using MozRepl and MozRepl::RemoteObject
by marto (Chancellor) on Nov 04, 2013 at 14:27 UTC
Re: Problem using MozRepl and MozRepl::RemoteObject
by Corion (Pope) on Nov 04, 2013 at 14:32 UTC

    If you want to automate Firefox, have you looked at WWW::Mechanize::Firefox?

    I don't know why/how your sample script fails for you, but you can enable verbose logging to the console to find out if/what error message you get from the Javascript.

      Thanks,
      I first experimented WWW::Mechanize::Firefox.
      My tests with simple examples usually work, but as soon as I try some more complicated tests, problems appear...
      Is it because of javascript ?
      Since I have decided to manipulate HTML with perl, I am still looking for the right solution...
      That's why I thought using directly mozrepl to drive Firefox could be a better solution, minimizing the intermediaries between Perl and Firefox.
      cf006

        I don't know what problems you experience. Maybe you can post a short, self-contained example that exhibits the problems?

        Personally, I use WWW::Mechanize::Firefox for lots of things without problems.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1061128]
Approved by keszler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-09-19 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls