0
votes

My selenium webdriver 'hello world' program is error-ing. Apologies since I am very new to this.

I spun up a new Ubuntu image and here is my setup:

  • Ubuntu 18.04 with Google Chrome installed
  • Ruby on Rails
  • selenium-webdriver gem installed
  • VNC is installed

My 'hello world' program:

        require "selenium-webdriver"
        **driver = Selenium::WebDriver.for :chrome**
        driver.navigate.to "http://www.google.com"
        element = driver.find_element(:name, 'q')
        element.send_keys "Hello Selenium WebDriver!"
        element.submit
        puts driver.title

This spits out the error:

/home/user/.rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.7/lib/selenium/webdriver/remote/response.rb:72:in `assert_ok': unknown error: Chrome failed to start: exited abnormally (Selenium::WebDriver::Error::UnknownError) (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=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 5.0.0-1028-gcp x86_64)

(This error happens at the boldfaced line of code)

I checked with whereis command for google-chrome and google-chrome-stable. They are both in /usr/bin/

I also have VNC installed and I am looking at the operating system. When I run this program, I am hoping for Chrome to pop out but nothing happens.

Is Selenium supposed to start chrome (visible to me in VNC)? In any case, what am I doing wrong?

1
Have you started Chrome with an active debugging port? stackoverflow.com/a/60008226/2662958 - snnguyen

1 Answers

0
votes

A few things can be going wrong here.

First things first, make sure you have an up-to-date copy of chromedriver installed on the machine. You can extract and place the executable in any location that's included in $PATH (echo $PATH to see where these directories are located).

If you're still having issues, it's worth trying to add the following options to the driver initialization, like this:

options = Selenium::WebDriver::Chrome::Options.new
options.headless!
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = Selenium::WebDriver.for :chrome, options: options

If that works for you, this may be an issue related to the x window manager that's installed (or not installed). Alternatively to messing around with something like that, you could check out XVFB to run selenium tests in.