Skip to content
Browse files

Prepare for translating to CSS over XPath (#37).

  • Loading branch information...
1 parent 069470f commit 73a10ddaa6d550cce06e8af7269abfc2fac89507 @jarib jarib committed Mar 23, 2012
View
6 lib/watir-webdriver/locators/button_locator.rb
@@ -16,7 +16,7 @@ def wd_find_first_by(how, what)
super
end
- def build_xpath(selectors)
+ def build_wd_selector(selectors)
return if selectors.values.any? { |e| e.kind_of? Regexp }
selectors.delete(:tag_name) || raise("internal error: no tag_name?!")
@@ -33,9 +33,9 @@ def build_xpath(selectors)
xpath << " | .//input"
xpath << "[#{input_attr_exp}]"
- p :build_xpath => xpath if $DEBUG
+ p :build_wd_selector => xpath if $DEBUG
- xpath
+ [:xpath, xpath]
end
def lhs_for(key)
View
6 lib/watir-webdriver/locators/child_cell_locator.rb
@@ -11,7 +11,7 @@ def by_id
nil
end
- def build_xpath(selectors)
+ def build_wd_selector(selectors)
return if selectors.values.any? { |e| e.kind_of? Regexp }
expressions = %w[./th ./td]
@@ -23,9 +23,9 @@ def build_xpath(selectors)
xpath = expressions.join(" | ")
- p :build_xpath => xpath if $DEBUG
+ p :build_wd_selector => xpath if $DEBUG
- xpath
+ [:xpath, xpath]
end
end # ChildCellLocator
View
6 lib/watir-webdriver/locators/child_row_locator.rb
@@ -11,7 +11,7 @@ def by_id
nil # avoid this
end
- def build_xpath(selectors)
+ def build_wd_selector(selectors)
return if selectors.values.any? { |e| e.kind_of? Regexp }
selectors.delete(:tag_name) || raise("internal error: no tag_name?!")
@@ -28,9 +28,9 @@ def build_xpath(selectors)
xpath = expressions.join(" | ")
- p :build_xpath => xpath if $DEBUG
+ p :build_wd_selector => xpath if $DEBUG
- xpath
+ [:xpath, xpath]
end
end # ChildRowLocator
View
28 lib/watir-webdriver/locators/element_locator.rb
@@ -75,14 +75,14 @@ def find_first_by_multiple
selector = normalized_selector
idx = selector.delete(:index)
- xpath = given_xpath(selector) || build_xpath(selector)
+ how, what = given_xpath(selector) || build_wd_selector(selector)
- if xpath
+ if how
# could build xpath for selector
if idx
- @wd.find_elements(:xpath, xpath)[idx]
+ @wd.find_elements(how, what)[idx]
else
- @wd.find_element(:xpath, xpath)
+ @wd.find_element(how, what)
end
else
# can't use xpath, probably a regexp in there
@@ -101,9 +101,9 @@ def find_all_by_multiple
raise ArgumentError, "can't locate all elements by :index"
end
- xpath = given_xpath(selector) || build_xpath(selector)
- if xpath
- @wd.find_elements(:xpath, xpath)
+ how, what = given_xpath(selector) || build_wd_selector(selector)
+ if how
+ @wd.find_elements(how, what)
else
wd_find_by_regexp_selector(selector, :select)
end
@@ -132,9 +132,13 @@ def wd_find_by_regexp_selector(selector, method = :find)
selector[:id] = id_from_label(rx_selector.delete(:label)) || return
end
- xpath = build_xpath(selector) || raise("internal error: unable to build xpath from #{selector.inspect}")
+ how, what = build_wd_selector(selector)
+
+ unless how
+ raise Error, "internal error: unable to build WebDriver selector from #{selector.inspect}"
+ end
- elements = @wd.find_elements(:xpath, xpath)
+ elements = @wd.find_elements(how, what)
elements.__send__(method) { |el| matches_selector?(el, rx_selector) }
end
@@ -264,7 +268,7 @@ def should_use_label_element?
@selector[:tag_name] != "option"
end
- def build_xpath(selectors)
+ def build_wd_selector(selectors)
return if selectors.values.any? { |e| e.kind_of? Regexp }
xpath = ".//"
@@ -283,7 +287,7 @@ def build_xpath(selectors)
p :xpath => xpath, :selectors => selectors if $DEBUG
- xpath
+ [:xpath, xpath]
end
def attribute_expression(selectors)
@@ -340,7 +344,7 @@ def given_xpath(selector)
raise ArgumentError, ":xpath cannot be combined with other selectors (#{selector.inspect})"
end
- xpath
+ [:xpath, xpath]
end
def can_be_combined_with_xpath?(selector)
View
6 lib/watir-webdriver/locators/text_field_locator.rb
@@ -11,7 +11,7 @@ def locate_all
private
- def build_xpath(selectors)
+ def build_wd_selector(selectors)
return if selectors.values.any? { |e| e.kind_of? Regexp }
selectors.delete(:tag_name)
@@ -28,9 +28,9 @@ def build_xpath(selectors)
xpath << "| .//textarea"
xpath << "[#{textarea_attr_exp}]" unless textarea_attr_exp.empty?
- p :build_xpath => xpath if $DEBUG
+ p :build_wd_selector => xpath if $DEBUG
- xpath
+ [:xpath, xpath]
end
def lhs_for(key)

0 comments on commit 73a10dd

Please sign in to comment.
Something went wrong with that request. Please try again.