Hello Perl world ! I would like to do a test . I have this code but when i launch it i have an 'unexpected' error in my Shell. Here my code :

use strict; package MyTestingSuite; use parent 'Test::Class'; use Test::Selenium::Remote::Driver; use Test::More; use Selenium::Remote::WebElement; sub startup : Test( startup => no_plan ) { my $self = shift; $self->{browsers} = [('chrome', 'internet explorer', 'phantomJS', 'f +irefox')]; } sub title_test : Tests { my $self = shift; foreach my $browser (@{$self->{browsers}}) { my $driver = Selenium::Remote::Driver->new( browser_name => $brows +er); $driver->get_ok("http://localhost"); $driver->pause(2000); $driver->set_window_size(640, 480); if($driver->find_element_ok('login','name')){ $driver->find_element('login','name') } if($driver->find_element_ok('password','name')){ $driver->find_element('password','name') } #$twd->click_element_ok($search_target [,$finder ,$desc]); $elem = $driver->find_element('submit','id'); $driver->mouse_move_to_location(element => $elem); # xoffset => x, + yoffset => y $driver->click_ok('LEFT'); $driver->pause(2000); $driver->maximize_window(); $driver->pause(2000); $driver->title_is('M.E'); $driver->capture_screenshot("D:/snap-$browser.png"); #$elem = find_element_by_class("dx-focused"); #$driver->mouse_move_to_location(element => $elem); #$driver->click('LEFT'); #ok($driver->get_title =~ /Google/,"title matches google"); #is($driver->get_title,'Google',"Title is google"); #ok($driver->get_title eq 'Google','Title equals google'); #like($driver->get_title,qr/Google/,"Title matches google"); $driver->quit(); } } sub element_test : Tests { my $self = shift; foreach my $browser (@{$self->{browsers}}) { my $driver = Selenium::Remote::Driver->new( browser_name => $brows +er); $driver->get("http://www.google.com"); $driver->pause(2000); $driver->set_window_size(640, 480); $driver->find_element('q','name'); $driver->find_element('btnG','name'); $driver->quit(); } } 1;

Here shell message : Global symbol "$elem" requires explicit package name at MyTestingSuite.pm line 29. Global symbol "$elem" requires explicit package name at MyTestingSuite.pm line 30.

Why ? Thanks !


In reply to Weird error ! by Chaoui05

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.