Solution 1 - Selenium :: WebDriver :: Chrome.driver_path =
There is a method Selenium::WebDriver::Chrome.driver_path= , which allows you to specify the binary code of the chrome edge:
require 'watir'
Solution 2 - Specify: driver_path_ during browser initialization
Alternatively, you can also specify the path to the driver when initializing the browser. This is slightly better in that you do not need to have Selenium code, but will repeat if you initialize the browser in different places.
# Determine the driver path chromedriver_path = File.join(File.absolute_path('../..', File.dirname(__FILE__)),"browsers","chromedriver.exe")
Solution 3 - Update ENV ['PATH']
When I initially answered this question, for some reason, I was not able to get the above solution to work. The value setting was apparently not used when Selenium-WebDriver started the driver. Although the first solution is recommended, it is an alternative.
Another option is to programmatically add the desired directory to the path that is stored in ENV['PATH'] . You can see in Selenium :: WebDriver :: Platform that the binary is located, checking if the executable exists in any of the folders in the path (starting from version 2.44.0):
def find_binary(*binary_names) paths = ENV['PATH'].split(File::PATH_SEPARATOR) binary_names.map! { |n| "#{n}.exe" } if windows? binary_names.each do |binary_name| paths.each do |path| exe = File.join(path, binary_name) return exe if File.executable?(exe) end end nil end
To specify the folder containing the binary, you just need to change ENV['PATH'] (add directory):
require 'watir'
Justin ko
source share