Perlchaoui has asked for the wisdom of the Perl Monks concerning the following question:
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:
And here the main code: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.
#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Screenshot with Perl
by poj (Abbot) on Nov 12, 2018 at 10:13 UTC | |
by Perlchaoui (Sexton) on Nov 12, 2018 at 11:21 UTC | |
by AnomalousMonk (Archbishop) on Nov 12, 2018 at 21:12 UTC | |
by Anonymous Monk on Nov 12, 2018 at 12:08 UTC | |
by Perlchaoui (Sexton) on Nov 12, 2018 at 12:53 UTC | |
by Your Mother (Archbishop) on Nov 12, 2018 at 22:56 UTC | |
|
Re: Screenshot with Perl
by Discipulus (Canon) on Nov 12, 2018 at 10:16 UTC | |
by Perlchaoui (Sexton) on Nov 12, 2018 at 11:31 UTC | |
by marto (Cardinal) on Nov 12, 2018 at 11:36 UTC | |
by Perlchaoui (Sexton) on Nov 12, 2018 at 12:58 UTC |