Hack-fix Selenium::WebDriver::Element#select is deprecated

Updated . Posted . Visible to the public.

In some older Capybara versions (e.g. 0.3.9), we're getting lots of deprecations warnings:

Selenium::WebDriver::Element#select is deprecated. Please use Selenium::WebDriver::Element#click and determine the current state with Selenium::WebDriver::Element#selected?

Hani-elabed on Github helps. Add this code to features/support/env.rb to remove them temporarily:

# June 30th, 2011
# a temporary hack to disable the annoying upstream warnings capybara > selenium-webdriver 0.2.2
# capybara folks know about this and are working on it. See:
# http://groups.google.com/group/ruby-capybara/browse_thread/thread/2cd042848332537a/7edb1699cb314862?show_docid=7edb1699cb314862
# Remove this whole block when Capybara 1.0.1 or greater are used
module Selenium
  module WebDriver
    class Element
      #
      # Select this element
      #

      def select
        #warn "#{self.class}#select is deprecated. Please use #{self.class}#click and determine the current state with #{self.class}#selected?"

        unless displayed?
          raise Error::ElementNotDisplayedError, "you may not select an element that is not displayed"
        end

        unless enabled?
          raise Error::InvalidElementStateError, "cannot select a disabled element"
        end

        unless selectable?
          raise Error::InvalidElementStateError, "you may only select options, radios or checkboxes"
        end

        click unless selected?
      end
    end
  end
end
Dominik Schöler
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2012-03-26 14:45)