Hello everybody ! Iam beginner with Perl. I would like to create one function to have all my code inside. And i would like to call it with 2 "same" calls. I did that but it doesn't work:
my $item; my $root = "'//a[@href="/"]'; my $name; sub myHomeTest { $elem = $driver->find_element('//a[@href="/"]'); # Other way to get + Xpath: $elem = $driver->find_element("//a[\@href='/']"); $driver->mouse_move_to_location(element => $elem); # xoffset => +x, yoffset => y $driver->click_element_ok('//a[@href="/license/view"]', 'xpath', + @name); $driver->pause(3000); $driver->capture_screenshot("$path/snapLicenseview-$browser.png" +); $driver->get_ok("$base_url","get Home url"); $driver->pause(2000); #return OneHome(); } myHomeTest (first var, second var,third,var); myHomeTest (first var, second var,third,var);
And my code is following:
$elem = $driver->find_element('//a[@href="/"]'); $driver->mouse_move_to_location(element => $elem); # xoffset => x, + yoffset => y $driver->click_element_ok('//a[@href="/license/view"]', 'xpath', ' +License View loaded'); $driver->pause(2000); $driver->capture_screenshot("$path/snapLicenseview-$browser.png"); $driver->get_ok("$base_url","Get Home url"); $driver->pause(2000); $elem = $driver->find_element('//a[@href="/"]'); $driver->mouse_move_to_location(element => $elem); # xoffset => x, + yoffset => y $driver->click_element_ok('//a[@href="/licenses"]', 'xpath', 'Lice +nses loaded'); $driver->pause(2000); $driver->capture_screenshot("$path/snapLicenses-$browser.png"); $driver->get_ok("$base_url", "get Home url"); $driver->pause(2000);
How can i do ? Thanks !

In reply to One function with 2 calls with Selenium 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.