Read more

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

Dominik Schöler
March 26, 2012Software engineer at makandra GmbH

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?
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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
Posted by Dominik Schöler to makandra dev (2012-03-26 16:45)