Forum: Ruby error with selenium-webdriver

249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2013-03-15 18:23
I am getting error with "selenium-webdriver". Any advice on that?


C:\>gem --list
ERROR:  Invalid option: --list.  See 'gem --help'.

C:\>gem --help
RubyGems is a sophisticated package manager for Ruby.  This is a
basic help message containing pointers to more information.

  Usage:
    gem -h/--help
    gem -v/--version
    gem command [arguments...] [options...]

  Examples:
    gem install rake
    gem list --local
    gem build package.gemspec
    gem help install

  Further help:
    gem help commands            list all 'gem' commands
    gem help examples            show some examples of usage
    gem help platforms           show information about platforms
    gem help <COMMAND>           show help on COMMAND
                                   (e.g. 'gem help install')
    gem server                   present a web page at
                                 http://localhost:8808/
                                 with info about installed gems
  Further information:
    http://guides.rubygems.org

C:\>gem list --local

*** LOCAL GEMS ***

bigdecimal (1.2.0)
childprocess (0.3.9)
ffi (1.4.0 x86-mingw32)
io-console (0.4.2)
json (1.7.7)
minitest (4.3.2)
multi_json (1.6.1)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
rubyzip (0.9.9)
selenium-webdriver (2.31.0)
test-unit (2.0.0.0)
websocket (1.0.7)

C:\>irb --simple-prompt
DL is deprecated, please use Fiddle
>> require "selenium-webdriver"
LoadError: cannot load such file -- ffi_c
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
 `require'
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
 `require'
        from
C:/Ruby200/lib/ruby/gems/2.0.0/gems/ffi-1.4.0-x86-mingw32/lib/ffi.r
b:12:in `rescue in <top (required)>'
        from
C:/Ruby200/lib/ruby/gems/2.0.0/gems/ffi-1.4.0-x86-mingw32/lib/ffi.r
b:3:in `<top (required)>'
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
 `require'
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
 `require'
        from
C:/Ruby200/lib/ruby/gems/2.0.0/gems/childprocess-0.3.9/lib/childpro
cess/windows.rb:1:in `<top (required)>'
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
 `require'
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
 `require'
        from
C:/Ruby200/lib/ruby/gems/2.0.0/gems/childprocess-0.3.9/lib/childpro
cess.rb:176:in `<top (required)>'
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
 `require'
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
 `require'
        from
C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.31.0/lib/s
elenium/webdriver.rb:1:in `<top (required)>'
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
 `require'
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
 `require'
        from
C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.31.0/lib/s
elenium-webdriver.rb:1:in `<top (required)>'
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:110:i
n `require'
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:110:i
n `rescue in require'
        from
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:35:in
 `require'
        from (irb):1
        from C:/Ruby200/bin/irb:12:in `<main>'>>
15000f55138ae94b0f362ed7c625461a?d=identicon&s=25 unknown (Guest)
on 2013-03-15 19:34
(Received via mailing list)
Please edit your posts to contain only the absolutely necessary
information.

Am 15.03.2013 18:23, schrieb Love U Ruby:

>
> C:\>gem --list
> ERROR:  Invalid option: --list.  See 'gem --help'.
>
> C:\>gem --help
> RubyGems is a sophisticated package manager for Ruby.  This is a
> basic help message containing pointers to more information.
>

[loooong help message]


All of the above (half of your post) is completely irrelevant.
249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2013-03-15 19:39
It's basically I means Ruby 2.0 is not working with
`selenium-webdriver`. When I wrote require 'selenium-webdriver',got the
above error. which is mentioned there.

Now I uninstall Ruby2.0 and reinstall Ruby 1.9.3, things now working.

So  I wanted to know - if ruby 2.0 is compatible with selenium or not?

Thanks
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2013-03-15 20:26
I tried selenium-webdriver with Ruby 2.0 as well and got the same error.
I don't know whether it's webdriver itself or some dependency which
isn't working though.
60b83bb4579cd684731a1709f85ee849?d=identicon&s=25 John W Higgins (Guest)
on 2013-03-15 21:09
(Received via mailing list)
So I'm certain you will follow none of the concepts shown below past 4
seconds after reading this but here goes yet again

On Fri, Mar 15, 2013 at 10:23 AM, Love U Ruby <lists@ruby-forum.com>
wrote:

> I am getting error with "selenium-webdriver". Any advice on that?
>
>
> >> require "selenium-webdriver"
> LoadError: cannot load such file -- ffi_c
>

Now what do you think the people making ruby would do when they emit an
error called "cannot load such file"? Could that possibly mean anything
at
all with regards to a problem? I mean one must first actually read their
screen prior to sending off an email begging for yet more help.

Now lets assume one looked at that and had any thought of wanting to
solve
their problem.

Step 1 - find where ffi_c comes from - Google will be our friend

"ruby ffi_c"

Out first hit is a stack overflow question about this exact error - but
it's old so it probably isn't fully valid but it's a step. Ok, so they
are
talking about back at the 1.1 vs 1.0.9 version of the gem and we are
currently at 1.4.0 on your system so it's not that - but we now know
that
it's the FFI gem. Google has done it's job again

Next step - google "ruby ffi gem" - first hit is rubygems.org -
outstanding
again Google. Going to that page shows that we've got recent activity in
the FFI world - at that would be the release of the 1.4.1 and 1.5.0
gems.

We now know that 2 versions of the code exist past yours - that's
outstanding because it means we might just have a possible fix already
packaged up for us.

Next, lets see what activity has been occurring in the source code - how
about we try that nice button marked "Source Code" on the RubyGems page.
That magically (via that great protocol called HTTP) brings us to
GitHub.com at the FFI source page. How about we see what the recent
commits
are shall we? That nice links called "1000+ commits" is the list of
commits
for the project. Pressing that reveals your EXACT answer - March 9th
2013,
"Add 2.0.0 binaries for win32" - you appear to be running win32 and
2.0.0
and I think that means that commit was for folks in your position. Now
we
look at the rest of the commits above it to see if we can determine what
version we might like - and looky there - March 10, 2013 "Bump version
to
1.5.0" - so which version do you think you might need to have a desire
to
have installed on your machine? Well to make it even simpler for you -
RubyGems lists the available versions - how about we go back there and
have
a look shall we? Looky there again - 2 big bright 1.5.0.pre1 gems all
nice
and pretty - you are running x86-mingw so you click on that nice link
under
the 1.5.0.pre1 link and you get a screen with a HUGE install right in
front
of you. That's the command you type in your command screen and you will
have the nice shiny new version of FFI which may or may not help you.

2 Google searches, common sense, and an answer - I've done my
humanitarian
work for the day.

And before anyone starts talking about rudeness or talking down or
anything
else about this email - I had no knowledge of what the possible solution
would have been prior to reading that email - but I actually used Google
twice and common sense. Why anyone in their right mind would be on the
bleeding edge (2.0) without the desire or ability to at least try
something
along the lines of what I did is the problem - not anything to do with
any
tonality in this email

John
249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2013-03-15 21:58
I was actually trying to write a script which will delete the files from
the webpage. But when I clicked on the delete button,one alert window is
coming to confirm finally before deletion.

So to handle this I wrote a code as below:

Part - I

alrt = Selenium::WebDriver::TargetLocator.new(driver).alert
alrt.accept

But then I was continually getting an error as below :

D:\Rubyscript\My ruby learning days\Scripts>W9_File_delete.rb
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/selenium/webdr
iver/common/alert.rb:9:in `initialize': undefined method `getAlertText'
for #<Se
lenium::WebDriver::Driver:0x..fa546df06 browser=:firefox>
(NoMethodError)
        from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/s
elenium/webdriver/common/target_locator.rb:76:in `new'
        from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.31.0/lib/s
elenium/webdriver/common/target_locator.rb:76:in `alert'
        from D:/Rubyscript/My ruby learning
days/Scripts/W9_File_delete.rb:114:i
n `<main>'

Now doing after too much research here :
http://www.rubydoc.info/gems/selenium-webdriver/frames

Finally I wrote the below :

part - II
driver.switch_to.alert.accept

and it works.

But If I followed the documentation I got the below:

#switch_to ~~>

----------------------------------------------------------
# File 'lib/selenium/webdriver/common/driver.rb', line 92

def switch_to
  @switch_to ||= WebDriver::TargetLocator.new(bridge)
end
-----------------------------------------------------------

Which is the same I did to get an object of `TargetLocator` in part - I.
then on that object I called `alert` to create `Alert` object and then
finally `accept` using `Alert` object.

Now my question is Why part - I has failed?

What was the wrong with my code ?

Although I fixed my code,but as for knowledge purpose I think should
know the wrong.

Could anyone help me on that context?
249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2013-03-18 09:52
Can anyone help me with the above confusions?

Thanks
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2013-03-22 10:08
The clue is this:
undefined method `getAlertText'
Find out where that's coming from using the backtrace above.

As always, watir-webdriver is simpler:
driver.alert.ok
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.