module Selenium::WebDriver::SearchContext
def extract_args(args)
def extract_args(args) case args.size when 2 args when 1 arg = args.first unless arg.respond_to?(:shift) raise ArgumentError, "expected #{arg.inspect}:#{arg.class} to respond to #shift" end # this will be a single-entry hash, so use #shift over #first or #[] arr = arg.dup.shift raise ArgumentError, "expected #{arr.inspect} to have 2 elements" unless arr.size == 2 arr else raise ArgumentError, "wrong number of arguments (#{args.size} for 2)" end end
def find_element(*args)
def find_element(*args) how, what = extract_args(args) by = SearchContext.finders[how.to_sym] raise ArgumentError, "cannot find element by #{how.inspect}" unless by bridge.find_element_by by, what, ref end
def find_elements(*args)
def find_elements(*args) how, what = extract_args(args) by = SearchContext.finders[how.to_sym] raise ArgumentError, "cannot find elements by #{how.inspect}" unless by bridge.find_elements_by by, what, ref end
def finders
def finders FINDERS.merge(extra_finders || {}) end