lib/watir-webdriver/elements/input.rb in watir-webdriver-0.0.6 vs lib/watir-webdriver/elements/input.rb in watir-webdriver-0.0.7
- old
+ new
@@ -2,10 +2,24 @@
module Watir
class Input < HTMLElement
alias_method :readonly?, :read_only?
+ #
+ # @private
+ #
+ # subclasses can use this to validate the incoming element
+ #
+
+ def self.from(parent, element)
+ unless element.tag_name == "input"
+ raise TypeError, "can't create #{self} from #{element.inspect}"
+ end
+
+ new(parent, :element => element)
+ end
+
def enabled?
!disabled?
end
#
@@ -29,27 +43,52 @@
#
# this is mostly useful if you're using Browser#element_by_xpath, and want to
# 'cast' the returned Input instance to one of the subclasses
#
+ #
+ # @return [Watir::CheckBox]
+ #
+
def to_checkbox
assert_exists
- Watir::CheckBox.new(@parent, :element, @element)
+ CheckBox.from(@parent, @element)
end
+ #
+ # @return [Watir::Radio]
+ #
+
def to_radio
assert_exists
- Watir::Radio.new(@parent, :element, @element)
+ Radio.from(@parent, @element)
end
+ #
+ # @return [Watir::Button]
+ #
+
def to_button
assert_exists
- Watir::Button.new(@parent, :element, @element)
+ Button.from(@parent, @element)
end
+
+ #
+ # @return [Watir::TextField]
+ #
- def to_select_list
+ def to_text_field
assert_exists
- Watir::SelectList.new(@parent, :element, @element)
+ TextField.from(@parent, @element)
+ end
+
+ #
+ # @return [Watir::FileField]
+ #
+
+ def to_file_field
+ assert_exists
+ FileField.from(@parent, @element)
end
end # Input
end # Watir