lib/watir/locators/element/locator.rb in watir-6.0.0.beta3 vs lib/watir/locators/element/locator.rb in watir-6.0.0.beta4

- old
+ new

@@ -26,12 +26,12 @@ [^|]*? # do not try to convert expressions with alternates ([^\[\]\\^$.|?*+()]*) # trailing literal characters \z }x - def initialize(parent, selector, selector_builder, element_validator) - @parent = parent # either element or browser + def initialize(query_scope, selector, selector_builder, element_validator) + @query_scope = query_scope # either element or browser @selector = selector.dup @selector_builder = selector_builder @element_validator = element_validator end @@ -70,11 +70,11 @@ selector.delete(:id) tag_name = selector.delete(:tag_name) return unless selector.empty? # multiple attributes - element = @parent.wd.find_element(:id, id) + element = @query_scope.wd.find_element(:id, id) return if tag_name && !element_validator.validate(element, selector) element end @@ -96,13 +96,13 @@ how, what = selector_builder.build(selector) if how # could build xpath/css for selector if idx - @parent.wd.find_elements(how, what)[idx] + @query_scope.wd.find_elements(how, what)[idx] else - @parent.wd.find_element(how, what) + @query_scope.wd.find_element(how, what) end else # can't use xpath, probably a regexp in there if idx wd_find_by_regexp_selector(selector, :select)[idx] @@ -130,19 +130,19 @@ raise ArgumentError, "can't locate all elements by :index" end how, what = selector_builder.build(selector) if how - @parent.wd.find_elements(how, what) + @query_scope.wd.find_elements(how, what) else wd_find_by_regexp_selector(selector, :select) end end def wd_find_all_by(how, what) if what.is_a? String - @parent.wd.find_elements(how, what) + @query_scope.wd.find_elements(how, what) else all_elements.select { |element| fetch_value(element, how) =~ what } end end @@ -158,31 +158,31 @@ element.attribute(how.to_s.tr("_", "-").to_sym) end end def all_elements - @parent.wd.find_elements(xpath: ".//*") + @query_scope.wd.find_elements(xpath: ".//*") end def wd_find_first_by(how, what) if what.is_a? String - @parent.wd.find_element(how, what) + @query_scope.wd.find_element(how, what) else all_elements.find { |element| fetch_value(element, how) =~ what } end end def wd_find_by_regexp_selector(selector, method = :find) - parent = @parent.wd + query_scope = @query_scope.wd rx_selector = delete_regexps_from(selector) if rx_selector.key?(:label) && selector_builder.should_use_label_element? label = label_from_text(rx_selector.delete(:label)) || return if (id = label.attribute(:for)) selector[:id] = id else - parent = label + query_scope = label end end how, what = selector_builder.build(selector) @@ -197,11 +197,11 @@ predicates = regexp_selector_to_predicates(key, value) what = "(#{what})[#{predicates.join(' and ')}]" unless predicates.empty? end end - elements = parent.find_elements(how, what) + elements = query_scope.find_elements(how, what) elements.__send__(method) { |el| matches_selector?(el, rx_selector) } end def delete_regexps_from(selector) rx_selector = {} @@ -215,10 +215,10 @@ rx_selector end def label_from_text(label_exp) # TODO: this won't work correctly if @wd is a sub-element - @parent.wd.find_elements(:tag_name, 'label').find do |el| + @query_scope.wd.find_elements(:tag_name, 'label').find do |el| matches_selector?(el, text: label_exp) end end def matches_selector?(element, selector)