Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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:

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=" +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/ 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.

Replies are listed 'Best First'.
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.

      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.

        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.

Re: Problem using MozRepl and MozRepl::RemoteObject
by marto (Bishop) on Nov 04, 2013 at 14:27 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1061128]
Approved by keszler
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2017-02-25 18:52 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (367 votes). Check out past polls.