I try to move Chrome by writing MacOS-X and Selenium in Ruby, but it doesn't work.The Ruby and Selenium installation went well, but I'm into ChromeDriver installation.
Specifically, use irb to
require "selenium-webdriver"
driver=Selenium::WebDriver.for:Chrome
Even if I do,
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.More info at http://code.google.com/p/selenium/wiki/ChromeDriver.
from/Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/chrome/service.rb:20:in `executable_path'
from/Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/chrome/service.rb:33:in `default_service'
from/Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/chrome/bridge.rb: 14: in `initialize'
from/Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/common/driver.rb:37:in `new'
from/Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/common/driver.rb:37:in `for'
from/Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver.rb:67:in `for'
from (irb): 3
from/usr/bin/irb:12:in `<main>'
I get scolded.
I've looked it up on the Internet, but it doesn't work.
Chromedriver is
/Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/
The .bashrc also describes the path to this directory.
What else is wrong?
ruby macos google-chrome selenium
I have never worked with Selenium+Chrome, but I have checked to see if the same problem occurs.
As a result, it worked fine in my environment.
I have created a program to verify the operation, so what are the results of this?
https://github.com/JunichiIto/selenium-chrome-sandbox
git clone [email protected]: JunichiIto/selenium-chrome-sandbox.git
cd selenium-chrome-sandbox
bundle install
# Loading the chromedriver in the operational verification program
PATH=$PATH:./bin bundle exec ruby./chrome.rb
# Loading the chromedriver present in the PATH of the system
bundle exec ruby./chrome.rb
start
Checking/usr/local/sbin/chromedriver, Exists?=false, executable?=false
Checking/usr/local/bin/chromedriver, Exists?=false, executable?=false
.
.
.
Checking./bin/chromedriver, Exists?=true, executable?=true
FOUND./bin/chromedriver
done
start
Checking/usr/local/sbin/chromedriver, Exists?=false, executable?=false
Checking/usr/local/bin/chromedriver, Exists?=false, executable?=false
.
.
.
Checking/sbin/chromedriver, Exists?=false, executable?=false
NOT FOUND!!
/Users/jit/.rbenv/versions/2.0.0-p598/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/chrome/service.rb:20:in `executable_path': 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. More info at http://code.google.com/p/selenium/wiki/ChromeDriver. (Selenium::WebDriver::Error::WebDriverError)
from/Users/jit/.rbenv/versions/2.0.0-p598/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/chrome/service.rb:33:in`default_service'
from/Users/jit/.rbenv/versions/2.0.0-p598/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/chrome/bridge.rb:14:in `initialize'
from/Users/jit/.rbenv/versions/2.0.0-p598/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/common/driver.rb:37:in`new'
from/Users/jit/.rbenv/versions/2.0.0-p598/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver/common/driver.rb:37:in`for'
from/Users/jit/.rbenv/versions/2.0.0-p598/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.45.0/lib/selenium/webdriver.rb:67:in`for'
from./chrome.rb:27:in `<main>'
The find_binary
method is a transplant of the logic used by selenium-webdriver.
The find_binary
method has the logic of checking all PATH-acquired directories for executables named chromedriver, returning the path when found, and returning nil
if not found.
#See https://code.google.com/p/selenium/source/browse/rb/lib/selenium/webdriver/common/platform.rb#138
def find_binary(*binary_names)
paths = ENV ['PATH'].split(File::PATH_SEPARATOR)
binary_names.each do | binary_name |
paths.each do | path |
exe=File.join(path,binary_name)
puts "Checking #{exe}, Exists?=#{File.exist?(exe)}, executable?=#{File.executable?(exe)}"
return if File.executable?(exe)
end
end
nil
end
# See https://code.google.com/p/selenium/source/browse/rb/lib/selenium/webdriver/chrome/service.rb#19
path = find_binary "chromedriver"
Check the terminal to see if the chromedriver has a path.
Below is my mac environment.Installing chromedriver on /usr/local/bin
$which chromedriver
/usr/local/bin/chromedriver
$ chromedriver --help
Usage—chromedriver [OPTIONS]
Options
--port = PORT port to listen on
--adb-port = PORT adb server port
--log-path = FILE write server log to file installed of stderr, increases log level to INFO
-- verbose log verbosely
--silent log nothing
-- url-base base URL path prefix for commands, e.g.wd/url
-- port-server address of server to contact for reserving a port
If it is not installed where the path goes, download it from the following URL in the error message and install it.
http://chromedriver.storage.googleapis.com/index.html
Also, Chrome must be installed in the application folder.
/Applications/Google\Chrome.app/Contents/MacOS/Google\Chrome
© 2024 OneMinuteCode. All rights reserved.