lib/celerity/element_locator.rb in jarib-celerity-0.0.6.7 vs lib/celerity/element_locator.rb in jarib-celerity-0.0.6.8

- old
+ new

@@ -1,11 +1,11 @@ module Celerity # # Used internally to locate elements on the page. - # - + # + class ElementLocator include Celerity::Exception attr_accessor :idents @@ -33,12 +33,10 @@ when :object unless what.is_a?(HtmlUnit::Html::HtmlElement) || what.nil? raise ArgumentError, "expected an HtmlUnit::Html::HtmlElement subclass, got #{what.inspect}:#{what.class}" end return what - when :id - return find_by_id(what) when :xpath return find_by_xpath(what) when :label return find_by_label(what) unless @attributes.include?(:label) when :class_name @@ -47,11 +45,13 @@ how = :href when :caption how = :text end - if @attributes.include?(how = how.to_sym) + if how == :id && conditions.size == 1 + return find_by_id(what) + elsif @attributes.include?(how = how.to_sym) attributes[how] << what elsif how == :index index = what.to_i - INDEX_OFFSET elsif how == :text text = what @@ -104,15 +104,15 @@ return ref if @tags.include?(ref.getTagName) find_by_id obj.getForAttribute end - def elements_by_idents(idents = nil) - get_by_idents(:select, idents || @idents) + def elements_by_idents(idents = @idents) + get_by_idents(:select, idents) end - def element_by_idents(idents = nil) - get_by_idents(:find, idents || @idents) + def element_by_idents(idents = @idents) + get_by_idents(:find, idents) end private def get_by_idents(meth, idents)