I'm trying to extract all the elements on a page that have links, then click each one. Some links lead to other pages not on the website, and others on the website. The site I'm testing has a index page for authors and other links. When I run the following code below, the browser executes the links that lead to the other sites and only on the first link of the author index.
#!/usr/bin/perl
use strict;
use warnings;
use Selenium::Remote::Driver;
use Test::More;
my $driver = Selenium::Remote::Driver->new( remote_server_addr => "localhost",
port => 4444,
browser_name => "firefox"
);
## redirect test ouput
Test::More->builder->output ('result.txt');
Test::More->builder->failure_output ('errors.txt');
## open url
## initializing variables
my @links_a = ();
## open file for printing lists to
open FILE, ">file.txt" or die $!;
## extract all links, by findind them via tag-name
@links_a = $driver->find_elements('a','tag_name');
## print all links to file
print (FILE "links: ", $_->get_attribute("href"),"\n") foreach (@links_a);
## testing click command
for (my $i =0; $i<@links_a ; $i++){
my $href = $links_a[$i]->get_attribute("href"
ok($links_a[$i]->click(), "$href");
# if ($href =~ m/AUTHOR/) $driver->go_back();
}
close FILE;
$driver->quit();