Liandro Cos
Liandro Cos

Reputation: 65

Selenium::Remote::Driver Driver info: driver.version: unknown

I can't run the script with the message: Driver info: driver.version: unknown

usloft5206:~/perl# java -Dwebdriver.chrome.bin="/usr/bin/google-chrome \
  --no-sandbox" -Dwebdriver.chrome.driver="/root/perl/chromedriver" \
  -Dwebdriver.chrome.whitelistedIps= \
  -jar /root/perl/selenium-server-standalone-3.141.59.jar
12:29:06.251 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
12:29:06.316 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444 2021-06-07
12:29:06.353:INFO::main: Logging initialized @298ms to org.seleniumhq.jetty9.util.log.StdErrLog
12:29:06.535 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
12:29:06.605 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444

The script chrome.pl:

#!/usr/bin/env perl

use strict;
use warnings;
use Selenium::Remote::Driver;
use Encode 'encode';

my $driver = Selenium::Remote::Driver->new(
  browser_name => 'chrome',
  extra_capabilities => { chromeOptions => {args => [
    'window-size=1920,1080',
    'headless',
  ]}},
);

my %visited = ();
my $depth = 1;
my $url = 'https://google.com/';

spider_site($driver, $url, $depth);

$driver->quit();

Output

usloft5206:~/perl# ./chrome.pl

Could not create new session: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Linux 3.10.0-1160.25.1.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 53 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'dominio.local', ip: '192.168.0.107', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.25.1.el7.x86_64', java.version: '1.8.0_292'
Driver info: driver.version: unknown at ./chrome.pl line 10.

usloft5206:~/perl# perl -v
This is perl 5, version 34, subversion 0 (v5.34.0) built for x86_64-linux

CentOS Linux release 7.9.2009 (Core)

usloft5206:~/perl# chromedriver -v
ChromeDriver 70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778)

usloft5206:~/perl# chromedriver -v
ChromeDriver 91.0.4472.19 (1bf021f248676a0b2ab3ee0561d83a59e424c23e-refs/branch-heads/4472@{#288})

selenium-server-standalone-3.141.59.jar

-sh-4.2$ google-chrome --no-sandbox
[28425:28425:0607/123836.573842:ERROR:browser_main_loop.cc(1402)] Unable to open X display.
-sh-4.2$ [0607/123836.579898:ERROR:nacl_helper_linux.cc(307)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly

Upvotes: 1

Views: 2365

Answers (1)

Zheng Li Sheng
Zheng Li Sheng

Reputation: 31

I believe your chrome and driver is not compatible.
The easy way is to install it using package manager.

# yum -y install epel-release chromium chromedriver
# java -Dwebdriver.chrome.driver=/usr/bin/chromedriver -jar [ your selenium standalone jar path ]

I'm assuming you got the reference code from https://www.perl.com/article/spidering-websites-with-headless-chrome-and-selenium/
It's spesific to https://example.com

Below codes work for me:

my $driver = Selenium::Remote::Driver->new(
  browser_name => 'chrome',
  extra_capabilities => { chromeOptions => {args => [
    'window-size=1920,1080',
    'headless',
    'no-sandbox',
  ]}},
);

my %visited = ();
my $depth = 1;
my $url = 'https://example.com';

spider_site($driver, $url, $depth);

$driver->quit();

sub spider_site {
  my ($driver, $url, $depth) = @_;
  warn "fetching $url\n";
  $driver->get($url);
  warn "survive get url\n";
  $visited{$url}++;

  my $text = $driver->get_title;
  warn "survive get title\n";
  print encode('UTF-8', $text);

  if ($depth > 0) {
    warn "finding element\n";
    my @links = $driver->find_elements('a', 'tag_name');
    my @urls = ();
    for my $l (@links) {
        warn "link: $l\n";
      my $link_url = eval { $l->get_attribute('href') };
      push @urls, $link_url if $link_url;
    }
    for my $u (@urls) {
        warn "calling spider_site for url $u";
      spider_site($driver, $u, $depth - 1) unless ($visited{$u});
    }
  }
}

Upvotes: 1

Related Questions