3

I've used homebrew to install the latest versions of geckodriver and chromedriver. I prefer the former, but would be willing to use either if they worked. I have installed with the cpan console the Selenium::Remote::Driver module as well, and it installed without any warnings. I am currently working from the example code snippets on https://metacpan.org/pod/Selenium::Remote::Driver .

use Selenium::Remote::Driver;
 
my $driver = Selenium::Remote::Driver->new;
$driver->get('http://www.google.com');
$driver->quit();

When I attempt to run the script, I receive the following error:

Selenium server did not return proper status at /Library/Perl/5.18/Selenium/Remote/Driver.pm line 544.

Now, I have no clue what I'm doing. And I'm working from some web sources that probably should be deprecated. Do I need to manually run geckodriver (or chromedriver) manually before I start this? If not, do I need to at least specify which to invoke in my code? Both are available in my path env. Is there some third component I've yet to install? A browser addon possibly?

My only goals are (at this point) to get it where it loads a web page into a browser (preferably not headless at this point in time, so that I can see it do what it does).

1

1 Answer 1

4

While Chrome-specific, the following is a minimal Selenium solution:

use FindBin          qw( $RealBin );
use Selenium::Chrome qw( );

my $web_driver = Selenium::Chrome->new(
   binary => "$RealBin/chromedriver.exe",
);

$web_driver->get('https://www.stackoverflow.com/');

$web_driver->shutdown_binary();

I wanted to handle exceptions, so I actually used this:

use FindBin             qw( $RealBin );
use Selenium::Chrome    qw( );
use Sub::ScopeFinalizer qw( scope_finalizer );

my $web_driver;
my $guard = scope_finalizer {
   if ($web_driver) {
      $web_driver->shutdown_binary();
      $web_driver = undef;
   }
};

$web_driver = Selenium::Chrome->new(
   binary => "$RealBin/chromedriver.exe",
);

$web_driver->get('https://www.stackoverflow.com/');
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. This answer has proved extremely helpful.... I had to remove .exe from mine (Mac, not Windows), but otherwise this works perfect. Some obvious substitutions even have the Firefox/gecko stuff working as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.