17

This problem is bugging me for a couple of days now... Whenever I'm using the .bring_to_front method

require "rubygems"
require "watir"

browser = Watir::Browser::new
browser.bring_to_front

I get this error:

(...)rubygems/custom_require.rb:36:in `require': no such file to load -- ffi_c (LoadError)

I tried uninstalling and reinstalling ffi/watir/ruby/netbeans without success.

line 36 is in custom_require.rb

def require path
if Gem.unresolved_deps.empty? or Gem.loaded_path? path then
  gem_original_require path
else
  spec = Gem.searcher.find_active path
  unless spec then
    found_specs = Gem.searcher.find_in_unresolved path
    unless found_specs.empty? then
      found_specs = [found_specs.last]
    else
      found_specs = Gem.searcher.find_in_unresolved_tree path
    end
    found_specs.each do |found_spec|
      Gem.activate_spec found_spec
    end
  end
  return gem_original_require path #problem
end

* LOCAL GEMS *

archive-tar-minitar (0.5.2)
builder (3.0.0)
childprocess (0.2.2)
columnize (0.3.4)
commonwatir (2.0.4)
ffi (1.0.10 x86-mingw32)
firewatir (1.9.4, 1.8.1)
hoe (2.12.3, 2.8.0)
json (1.6.1)
json_pure (1.6.1)
linecache19 (0.5.12)
minitest (2.7.0, 2.6.2, 1.6.0)
nokogiri (1.5.0 x86-mingw32)
rake (0.9.2.2, 0.9.2, 0.8.7)
rautomation (0.6.3)
rdiscount (1.6.8)
rdoc (3.11, 2.5.8)
require_all (1.2.0)
ruby-debug-base19 (0.11.25)
ruby-debug-ide (0.4.16, 0.4.9)
ruby_core_source (0.1.5)
rubyzip (0.9.4)
s4t-utils (1.0.4)
selenium-webdriver (2.10.0)
user-choices (1.1.6.1)
watir (2.0.4)
watir-webdriver (0.3.5)
win32-api (1.4.8 x86-mingw32)
win32-process (0.6.5)
windows-api (0.4.0)
windows-pr (1.2.1)
xml-simple (1.1.1, 1.1.0)
drake10k
  • 415
  • 1
  • 5
  • 21
  • 1
    0) works for me with ruby 1.9.2 and Watir 2.0.3 1) what version of Watir are you using. 2) We need more of the error. Line 36 in the indicated file is working with a parameter passed to that method, need to see where what called that line. 3) Can you do 'Gem List' from the command line and add that info to your question. – Chuck van der Linden Nov 01 '11 at 21:13
  • Thanks for including the additional info, however it's more of the actual ERROR that I wanted to see, I'd already gone and looked at the custom_require file.. – Chuck van der Linden Nov 02 '11 at 22:28
  • possible duplicate of https://stackoverflow.com/q/65000467/12544391, e.g. adding `gem "ffi"` to `Gemfile` fixed it – Dorian Aug 23 '21 at 17:13

2 Answers2

27

I think the missing file relates to the FFI gem. I had issues trying to use FFI v1.0.10 myself (when it went to install, and due to something pertaining to webdriver code) so on my box I have v1.0.9 of that gem installed.

I'd say there's not much to lose by trying to roll that gem back a version. From the command line type

gem uninstall ffi

once it's done then

gem install ffi -v 1.0.9

See if that fixes things for you.

Update the FFI gem has since updated past 1.1.0 and these versions seem to work fine with watir and watir-webdriver, however the gem is not pre-compiled, and has to compile code when it installs. This means if you are running on a PC you will need to install the Ruby development kit for windows, aka 'devkit', you can get it from the downloads page on the rubyinstaller site

download and install devkit first, then open a new command line window and use

gem install ffi

to get the latest version of the FFI gem

if for some reason that does not work for you, you can always use the original instructions above to install the slightly older version of the FFI gem

Chuck van der Linden
  • 6,660
  • 2
  • 28
  • 43
  • 1
    thank you very much. Had same issue, found this and it resolved my issue as well. – Bryce Fischer Dec 21 '11 at 16:01
  • FFi is used by bundle, so how to tell bundle, where my later (1.9.6) instance of FFI is? When I bundle install, later FFI (1.9.6) is replaced by older (1.9.3), which not working. – liquide Mar 13 '15 at 08:39
  • After having been trying to install ffi version 1.0.9 at above instructed steps, I encountered next error, which says; Fetching: ffi-1.0.9.gem (100%) ERROR: Error installing ffi: The 'ffi' native gem requires installed build tools. Please update your PATH to include build tools or download the DevKit from 'http://rubyinstaller.org/downloads' and follow the instructions at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit' – Yuya Kobayashi Mar 18 '15 at 08:35
  • So I couldn't install versionn 1.0.9 of ffi after ffi yet. – Yuya Kobayashi Mar 18 '15 at 08:36
  • After avoiding the use of the latest version of ruby as of Ruby 2.2.1 (x64) but rather 2.0.0-p643 (x64), installation of Ruby, its gem and devkit were all succeeded. – Yuya Kobayashi Mar 20 '15 at 05:03
  • The error told you what to do to fix the problem.. properly install devkit `Please update your PATH to include build tools or download the DevKit from 'rubyinstaller.org/downloads'; and follow the instructions at 'github.com/oneclick/rubyinstaller/wiki/Development-Kit` – Chuck van der Linden Apr 15 '15 at 21:05
  • I had to remove ffi (all versions) by running `gem uninstall ffi` and then run `bundle` – Ray Jun 07 '22 at 13:18
0

gem install ffi --pre

The above command worked for me under windows

P Emp
  • 1
  • 2