Hello,
I am trying to open two pages at the same time, in two different tabs, with WWW::Mechanize::Firefox.

I need to read information in these two pages, and don't want to open them one after the other, as i have to wait a bit of time, for the pages to load.

How could i do this?

Because i need to read information in both at the same time, i thought that i needed to open two www::Mechanize::Firefox objects/browsers at the same time. Is that wrong ?
Here is what i have tried, and the results i obtained :

1. create two different WWW::Mechanize::Firefox objects one after the other.
=> seems to work (at least for opening the two pages in two different tabs), but i get this warning when i create the second browser:
Subroutine MozRepl::__load_plugins redefined at C:/strawberry/perl/site/lib/Module/Pluggable/Fast.pm line 104, <DATA> line 1.
Shall i just ignore it?
Edit : i just tried it again and this time it works without warning... All good, then?

2. get the current browser's Firefox::Application, open a new tab and select it. finally, try to use the Application's browser with Firefox::Application::browser(), and get() a page with it.
=> it gives me this output :
Use of uninitialized value in concatenation (.) or string at C:/strawberry/perl/site/lib/MozRepl/RemoteObject.pm line 835, <> line 3. MozRepl::RemoteObject: : Object has no function get at test_tabs_application.pl line 72.
I suppose it was simply not the right thing to do.

What is the right way to do this?

Here is the code that i used for these two methods:
1. Opening two browsers, one after the other (it seems to work without warning now):

#!/usr/bin/perl use 5.012003; # Perl version requirement use strict; use warnings; #comment before releasing use autodie 2.10; use Carp 1.25; use Perl6::Say 0.16; use Readonly 1.03; # ##### use WWW::Mechanize::Firefox 0.59; # where is my Firefox executable ? Readonly my $FIREFOX_FOLDER => 'C:\Program Files\Mozilla Firefox\firefox.exe'; # ###### # URL address of the two pages that we want to open in two tabs Readonly my $URL_1 => 'http://www.perlmonks.org/?node_id=958952'; Readonly my $URL_2 => 'http://www.perlmonks.org/?node_id=907951'; # start browser 1 my $browser_1 = WWW::Mechanize::Firefox->new( # launch Firefox if it is not already running launch => $FIREFOX_FOLDER, ); croak 'Could not initialize the browser' if !$browser_1->success(); say '# Browser 1 is now ready to go'; # open page 1 $browser_1->get( $URL_1 ); croak 'Could not open page 1' if !$browser_1->success(); say '# Page 1 opened'; # start browser 2 say '# now creating a second WWW::MEchanize::Firefox browser'; my $browser_2 = WWW::Mechanize::Firefox->new( # launch Firefox if it is not already running launch => $FIREFOX_FOLDER, ); croak 'Could not initialize the browser' if !$browser_2->success(); say '# Browser 2 is now ready to go'; # open page 2 $browser_2->get( $URL_2 ); croak 'Could not open page 2' if !$browser_2->success(); say '# Page 2 opened'; # stop the program, so i can check which pages have been opened say '# done !'; my $stop = <ARGV>;

2. Trying to use Firefox::Aplication::browser() :
#!/usr/bin/perl use 5.012003; # Perl version requirement use strict; use warnings; #comment before releasing use autodie 2.10; use Carp 1.25; use Perl6::Say 0.16; use Readonly 1.03; # ##### use WWW::Mechanize::Firefox 0.59; # where is my Firefox executable ? Readonly my $FIREFOX_FOLDER => 'C:\Program Files\Mozilla Firefox\firefox.exe'; # ###### # URL address of the two pages that we want to open in two tabs Readonly my $URL_1 => 'http://www.perlmonks.org/?node_id=958952'; Readonly my $URL_2 => 'http://www.perlmonks.org/?node_id=907951'; # start the browser my $browser_1 = WWW::Mechanize::Firefox->new( # launch Firefox if it is not already running launch => $FIREFOX_FOLDER, ); croak 'Could not initialize the browser' if !$browser_1->success(); say '# A browser is now ready to go'; # open page 1 $browser_1->get( $URL_1 ); croak 'Could not open page 1' if !$browser_1->success(); say '# Page 1 opened'; # open a new tab my $Firefox_application = $browser_1->application(); my $old_tab = $Firefox_application->selectedTab(); say '# old tab recorded'; my $new_tab = $Firefox_application->addTab(); say '# new tab opened'; # get the new tab's browser my $browser_2 = $Firefox_application->browser(); say "# new tab's browser ready to go"; # bring the new tab in the foreground $Firefox_application->activateTab( $new_tab ); # bring to foreground say '# the new tab is now in the foreground'; # open page 2 say '# Now trying to open the page 2 with get($URL_2)'; $browser_2->get( $URL_2 ); say '# Page 2 opened in new tab'; # stop the program, so i can check which pages have been opened say '# done !'; my $stop = <ARGV>;


In reply to How to control two tabs at the same time with WWW::Mechanize::Firefox by mascip

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.