2

Wie würde ich eine Registerkarte basierend auf dem Titel mit WWW::Mechanize::Firefox schließen? HierSchließen Tab basierend auf Titel

ist, was ich habe zur Zeit:

my $ff = Firefox::Application->new(); 
my @tab_info = $ff->openTabs(); 
foreach my $tab (@tab_info) { 
    if($tab->{title} eq "TITLE HERE") { 
     $ff->closeTab($tab->{location}); 
    } 
} 

Die Dokumentation für closeTab() nur sagt: ‚Schließen Sie die Gegeben Tab‘ ohne Informationen darüber, was die gegebene Registerkarte

Antwort

2

Es $ff->closeTab($tab->{tab}) ist. Siehe zum Beispiel die Cookbook. Ein komplettes Programm:

use WWW::Mechanize::Firefox;  
my $ff = Firefox::Application->new(); 

my $title_to_close = "Title of the page to close ..."; 

# This will pull in all currently opened tabs 
my @tabs = $ff->openTabs(); 

foreach my $tab (@tabs) { 
    if ($tab->{title} =~ /$title_to_close/) { 
     print "Close tab: $tab->{title}"; 
     $ff->closeTab($tab->{tab}); 
    } 
} 
1

prägnante:

$ff->closeTab($_->{tab}) for grep { $_->{title} eq 'TITLE HERE' } $ff->openTabs;