title: Selenium headless does not run on CentOS 7 with Perl, "no display specified"
body: <p>I try to run headless Selenium on CentOS7:</p>
  
  <pre><code># cat /etc/os-release 
  NAME="Red Hat Enterprise Linux Server"
  VERSION="7.2 (Maipo)"
  </code></pre>
  
  <p>I installed Xvfb and run it as</p>
  
  <pre><code># /usr/bin/Xvfb :99
  </code></pre>
  
  <p>I installed firefox:</p>
  
  <pre><code># firefox -v
  Mozilla Firefox 38.5.0
  </code></pre>
  
  <p>and run it to check if it can be run at all:</p>
  
  <pre><code># export DISPLAY=:99
  # firefox
  </code></pre>
  
  <p>This is the output:</p>
  
  <pre><code># firefox
  Xlib:  extension "RANDR" missing on display ":99".
  console.error: 
    [CustomizableUI]
    Custom widget with id loop-button does not return a valid node
  console.error: 
    [CustomizableUI]
    Custom widget with id loop-button does not return a valid node
  GLib-GIO-Message: Using the 'memory' GSettings backend.  Your settings will not be saved or shared with other applications.
  </code></pre>
  
  <p>Firefox seems to be running after that command:</p>
  
  <pre><code># ps aux | grep firefox
  root     29476  7.3 14.9 852356 152256 pts/3   Sl+  10:30   0:03 /usr/lib64/firefox/firefox
  </code></pre>
  
  <p><strong>EDIT</strong>
  Yes, it's running. Taking screenshot from the Xvfb by </p>
  
  <pre><code>DISPLAY=:99 import -window root -crop 1264x948+0+0  /tmp/screenshot.jpg
  </code></pre>
  
  <p>I can see
  <a href="https://i.stack.imgur.com/rVQnU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rVQnU.jpg" alt="enter image description here"></a></p>
  
  <p>Now the problematic part. </p>
  
  <p>I installed Selenium Remote Driver for perl</p>
  
  <pre><code># cpanm Selenium::Remote::Driver
  </code></pre>
  
  <p>Then I ran standalone selenium driver:</p>
  
  <pre><code># java -jar selenium-server-standalone-2.49.0.jar 
  </code></pre>
  
  <p>Now I run test script:</p>
  
  <pre><code>#!/usr/bin/perl
  use strict;
  use warnings;
  use Selenium::Remote::Driver;
  my $driver = Selenium::Remote::Driver-&gt;new(browser_name=&gt;'firefox');
  $driver-&gt;get('http://www.google.com');
  print $driver-&gt;get_title();
  $driver-&gt;quit();
  </code></pre>
  
  <p>After 45 second I get error from the driver:</p>
  
  <pre><code>Could not create new session: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
  Error: no display specified
   at (eval 89) line 510.
  </code></pre>
  
  <p>Seems like firefox launched by the driver does not see DISPLAY environment variable. I try to add it from the script:</p>
  
  <pre><code>#!/usr/bin/perl
  use strict;
  use warnings;
  use Selenium::Remote::Driver;
  $ENV{DISPLAY}=":99";
  my $driver = Selenium::Remote::Driver-&gt;new(browser_name=&gt;'firefox');
  $driver-&gt;get('http://www.google.com');
  print $driver-&gt;get_title();
  $driver-&gt;quit();
  </code></pre>
  
  <p>It does not help, the previous error remains. 
  What do I do?</p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>I tried the current setup with Python. All works.</p>
  
  <pre><code># pip install selenium
  </code></pre>
  
  <p>And used the following test script:</p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  
  driver = webdriver.Firefox()
  driver.get("http://www.python.org")
  f = open('ptn-sel.txt', 'w')
  f.write(driver.title)
  driver.close()
  f.close()
  </code></pre>
  
  <p>I understand it's problem of Perl driver.... Any suggestions?</p>