1

I'm trying to run a selenium ruby file (.rb) through command prompt in linux. I just need to launch chrome and get a url. So I downloaded and have Selenium-serverstandalone-2.37.0.jar and chromedriver (extracted from chromedriver_linux(32)) in the same directory (/home/). And I have set my path pointing to chromedriver also. I'm a starter, so pl let me know if I'm missing something here.

This is my test.rb file:

require "selenium-webdriver"
require "rspec"
include RSpec::Expectations

describe "TestScript" do

  before(:each) do
    @driver = Selenium::WebDriver.for :chrome
    @base_url = "http://www.google.com"
    @accept_next_alert = true
    @driver.manage.timeouts.implicit_wait = 5
    @verification_errors = []
  end

  after(:each) do
    @driver.quit
    @verification_errors.should == []
  end

  it "test_script" do
    @driver.get(@base_url)
    puts "Logged in"
    if(element_present?(:link, "Home"))
    puts "Home page is detected"
  end
   puts "Logging out"
 end

def element_present?(how, what)
    @driver.find_element(how, what)
    true
    rescue Selenium::WebDriver::Error::NoSuchElementError
    false
end

def verify(&blk)
  yield
  rescue ExpectationNotMetError => ex
  @verification_errors << ex
end

Whe I run it, it throws this error:

NoMethodError: undefined method 'quit' for Nil:NilClass occured at /home/test.rb

 Failure/Error: @driver = Selenium::WebDriver.for :chrome
 Selenium::WebDriver::Error::WebDriverError:
 Unable to find the chromedriver executable. Please download the server from http://chromedriver.storage.googleapis.com/index.html and place it somewhere on your path.

Please guide me how to proceed!

2 Answers 2

1

It is not enough to place the chromedriver executable in the same directory. You have to make sure that it is in a directory that is in your $PATH. You could put it in /usr/local/bin and make sure that /usr/local/bin is in $PATH.

You can check if /usr/local/bin already is in your $PATH with

echo $PATH | grep "/usr/local/bin"

if this outputs nothing, you need to add the following line to your shell config (e.g. ~/.bashrc if you're using Bash):

export PATH=/usr/local/bin:$PATH

then restart your shell and check again.

2
  • Thanks for the quick reply. I added the chromedriver for linux in the $PATH. But still I'm getting the same error!
    – Saran
    Dec 20, 2013 at 5:36
  • Can you please suggest me more improvements?
    – Saran
    Dec 20, 2013 at 6:25
0

Finally I got it working!! Switching to older version of selenium-standalone-server did the trick.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.