lib/watir-classic/input_elements.rb in watir-classic-4.0.1 vs lib/watir-classic/input_elements.rb in watir-classic-4.1.0

- old
+ new

@@ -8,10 +8,15 @@ attr_ole :value attr_ole :alt attr_ole :src attr_ole :type + # @return [String] text field label's text. + def label + @container.label(:for => id).text + end + # @private def locate @o = @container.locator_for(InputElementLocator, @specifiers, self.class).locate end @@ -38,12 +43,12 @@ # @macro exists # @macro enabled def select(item) matching_options = [] perform_action do - matching_options = matching_items_in_select_list(:text, item) + - matching_items_in_select_list(:label, item) + + matching_options = matching_items_in_select_list(:text, item) + + matching_items_in_select_list(:label, item) + matching_items_in_select_list(:value, item) raise NoValueFoundException, "No option with :text, :label or :value of #{item.inspect} in this select element" if matching_options.empty? matching_options.each(&:select) end first_present_option_value matching_options, :text @@ -175,15 +180,17 @@ alias_method :__value, :value # @return [String] button contents of value attribute or inner text if there's no value. # @see Element#text def text - val = __value + val = tag_name == "button" ? super : __value val.empty? ? super : val end - alias_method :value, :text + def value + tag_name == "button" ? attribute_value("value") : text + end end # Returned be {Container#text_field}. class TextField < InputElement attr_ole :size @@ -199,15 +206,10 @@ rescue WIN32OLERuntimeError 0 end end - # @return [String] text field label's text. - def label - @container.label(:for => name).text - end - # Clear the contents of the text field. # # @macro exists # @macro enabled # @raise [ObjectReadOnlyException] if the text field is read only. @@ -336,11 +338,11 @@ end # @private def assert_not_readonly if self.readonly? - raise ObjectReadOnlyException, + raise ObjectReadOnlyException, "Textfield #{@specifiers.inspect} is read only." end end private @@ -358,17 +360,17 @@ dispatch_event("onKeyUp") end end # Supports double-byte characters - def characters_in(value, &blk) + def characters_in(value, &blk) if RUBY_VERSION =~ /^1\.8/ index = 0 - while index < value.length + while index < value.length len = value[index] > 128 ? 2 : 1 yield value[index, len] index += len - end + end else value.each_char(&blk) end end