Perlchaoui has asked for the wisdom of the Perl Monks concerning the following question:

Hello dear Monastery

I am trying to automate the navigation within a website using an Excel file as data set. I am using Selenium::Remote::Driver as module. When i am trying to recover datas from , for instance, cell B1, i am getting an error related to the use of a "url" but nor in my script or in my Excel config file i am using an URL . So i really don't understand this issue..

Here the 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 ("SOGETI.csv"); my $data = $excel->[1]{B1}; $driver->get('http://www.google.com'); $driver->get($data); $driver->maximize_window(); $driver->find_element('q','name')->send_keys($data); $driver->pause(4000); my $filename = "screenshot.png"; $driver->capture_screenshot($filename); $driver->pause(2000); 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();

And below the output in my console

C:\Users\User1\Documents\TESTPERL>perl TEST.pl Error while executing command: invalid argument: 'url' must be a strin +g (Session info: chrome=70.0.3538.77) (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e +332711d2874a),platform=Windows NT 6.1.7601 SP1 x86_64) at C:/Strawber +ry/perl/site/lib/Selenium/Remot e/Driver.pm line 391. at C:/Strawberry/perl/site/lib/Selenium/Remote/Driver.pm line 348.

Is someone able to have a look to this issue please ?

Thanks in advance

Replies are listed 'Best First'.
Re: Recover Excel datas
by Corion (Patriarch) on Nov 14, 2018 at 13:49 UTC

    So, what is in $data? Maybe it is not an URL but something else?

    Try to print it to see what it contains.

      Just a string like "Test"

      But no URL

        Why are you treating a string "Test" as a valid URL and trying to visit it?

Re: Recover Excel datas
by bliako (Abbot) on Nov 14, 2018 at 16:34 UTC

    To me it seems you have a set of URLs in a CSV file and you want to visit them one-by-one and take a screenshot when their html renders.

    Why involve excel at all? (are your troubles not enough?). A CSV file can be parsed by much simpler methods, for example using Text::CSV, or by a regex.

    Secondly, in the above code you do not know where the error occurs. Indeed there is no mention of a line-number in your own code but there is a reference to some Selenium code. OK, that bugs me too - often I am in the same situation where I need to see where my program died. What I would do if I feel lazy is to insert a print "i am here 1\n"; exit(0); (incrementing 1 to 2, to 3 etc. for each line) in between each line after my $driver for a few lines and keep running the program until the message of death arrives. This is lame but hey it cost me 3 minutes (for that simple code) but eventually lead me to the root of it. I could even make a macro in my editor to do all the inserts for me.

    There is an easier way though which is to run perl in debug mode. This will tell you exactly where it died: perl -d <program-name> then press c to run it.

      Many thanks for your advices bliako

      I started with the idea to use an Excel file because in my company we are often using Excel spreadsheets

Re: Recover Excel datas
by marto (Cardinal) on Nov 14, 2018 at 13:52 UTC

      Hi Marto

      I am not totally agree. Here i am just trying to retrieve a simple data ( a string like "Test") from a cell in an Excel file. I don't want to recover an URL. I just don't understand why i got an URL linked error.

      But maybe i am wrong.

      Thanks again

        "I am not totally agree."

        Both errors you report are the same:

        C:\Users\User1\Documents\TESTPERL>perl TEST.pl Error while executing command: invalid argument: 'url' must be a strin +g (Session info: chrome=70.0.3538.77) (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e +332711d2874a),platform=Windows NT 6.1.7601 SP1 x86_64) at C:/Strawber +ry/perl/site/lib/Selenium/Remot e/Driver.pm line 391. at C:/Strawberry/perl/site/lib/Selenium/Remote/Driver.pm line 348.

        and

        C:\Users\user1\Documents\TESTPERL>perl TEST6.pl Error while executing command: invalid argument: 'url' must be a strin +g (Session info: chrome=70.0.3538.77) (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e +332711d2874a),platform=Windows NT 6.1.7601 SP1 x86_64) at C:/Strawber +ry/perl/sit e/lib/Selenium/Remote/Driver.pm line 391. at C:/Strawberry/perl/site/lib/Selenium/Remote/Driver.pm line 348.

        "Here i am just trying to retrieve a simple data ( a string like "Test") from a cell in an Excel file."

        This isn't what the code you posted does. You should ask who ever wrote the code for you.

        If you want a string from an Excel file, why do you need Selenium, and Google?

        Hi,

        "I just don't understand why i got an URL linked error."

        Because you place the value "Test" into the variable $data and then tell the Selenium Driver to get it.

        Hope this helps!


        The way forward always starts with a minimal test.