#!/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 = ; #### #!/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 = ;