To get working what you're trying to accomplish you have to take care about the scope of the $sel Object:
...
if (@commands){
my $sel = login();
do_changepass($sel);
}
sub login {
my $sel = WWW::Selenium->new( host => "localhost",
port => 4444,
browser => "*googlechrome",
browser_url => "example.com",
);
$sel->start;
$sel->open("/login.php");
$sel->wait_for_page_to_load("5000");
$sel->type("id=loginSection-username", "username");
$sel->type("id=loginSection-password", "password");
$sel->click("name=send");
$sel->wait_for_page_to_load("30000");
sleep(2);
return $sel;
}
sub do_changepass {
my $email = $changepass[0]; my $oldpass = $changepass[1]; my $newpass = $changepass[2];
my ($sel) = @_;
$sel->click("css=#my-webspaces-container .more > a");
$sel->wait_for_page_to_load("30000");
...MORE COMMANDS...
}
...
my
creates the variable with a lexical scope, so it will be gone after you leave the current block (and there are no references to it neither).
or you can use the login
-subroutine directly in the do_changepass
...
sub do_changepass {
my $email = $changepass[0]; my $oldpass = $changepass[1]; my $newpass = $changepass[2];
my ($sel) = login(); # <--- login used here!!!
$sel->click("css=#my-webspaces-container .more > a");
$sel->wait_for_page_to_load("30000");
...MORE COMMANDS...
}
...