Hello Monastery !

I would like to get an answer if possible on the below topic. I have to test several url's and i would like to do some screnshot for each of them, once the website is available.

I can do a screnshot using this code. It's working fine.

my $filename = "screenshot.png"; $driver->capture_screenshot($filename);

But as the screenshot action is part of a loop ,when doing that, each screenshot is overriding the previous one because of the same path.

I searched and i did the following change but this is not working. I can load my script but i recover no screnshot

my $path = "C:/Users/user1/Documents/TESTPERL"; $driver->capture_screenshot("$path/Website-$url.png");

The output in CMD is here:

C:\Users\user1\Documents\TESTPERL>perl TEST7.pl Processing https://www.tricentis.com/ binmode() on closed filehandle $fh at C:/Strawberry/perl/site/lib/Sele +nium/Remote/Driver.pm line 1014. print() on closed filehandle $fh at C:/Strawberry/perl/site/lib/Seleni +um/Remote/Driver.pm line 1015. Processing https://learn.perl.org/examples/spreadsheet_read.html binmode() on closed filehandle $fh at C:/Strawberry/perl/site/lib/Sele +nium/Remote/Driver.pm line 1014. print() on closed filehandle $fh at C:/Strawberry/perl/site/lib/Seleni +um/Remote/Driver.pm line 1015. Processing https://github.com/mozilla/geckodriver/releases binmode() on closed filehandle $fh at C:/Strawberry/perl/site/lib/Sele +nium/Remote/Driver.pm line 1014. print() on closed filehandle $fh at C:/Strawberry/perl/site/lib/Seleni +um/Remote/Driver.pm line 1015.
And here the main code:
#!/usr/bin/perl use strict; use warnings; use Test::More; #use Test::Time; use Selenium::Remote::Driver; use Selenium::Remote::WebElement; use Selenium::Remote::WDKeys; use Spreadsheet::Read; use Text::CSV_XS; my $driver = Selenium::Remote::Driver->new( 'remote_server_addr' => 'localhost', 'browser_name' => 'chrome', 'port' => '4444', ); my $excel = ReadData("TEST.csv"); my $row = 1; my $url = $excel->[1]{'A'.$row}; while ($url){ # do something with url process($url); ++$row; $url = $excel->[1]{'A'.$row}; } sub process { my ($url) = @_; print "Processing $url\n"; $driver->get($url); $driver->maximize_window(); $driver->pause(2000); #my $filename = "screenshot.png"; #$driver->capture_screenshot($filename); my $path = "C:/Users/user1/Documents/TESTPERL"; $driver->capture_screenshot("$path/Website-$url.png"); $driver->pause(2000); }

I already put this in a post but it was a remark part of another topic.

Can someone help on this ?

Many thanks


In reply to Screenshot with Perl by Perlchaoui

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.