lib/watir-webdriver/locators/element_locator.rb in watir-webdriver-0.6.4 vs lib/watir-webdriver/locators/element_locator.rb in watir-webdriver-0.6.5
- old
+ new
@@ -8,16 +8,18 @@
:class_name,
:css,
:id,
:link,
:link_text,
- # :name, # deliberately excluded to be watirspec compliant
+ :name,
:partial_link_text,
:tag_name,
:xpath
]
+ WILDCARD_ATTRIBUTE = /^(aria|data)_(.+)$/
+
def initialize(wd, selector, valid_attributes)
@wd = wd
@selector = selector.dup
@valid_attributes = valid_attributes
end
@@ -30,12 +32,14 @@
element = find_first_by_one
else
element = find_first_by_multiple
end
- # this actually only applies when finding by xpath - browser.text_field(:xpath, "//input[@type='radio']")
- # we don't need to validate the element if we built the xpath ourselves.
+ # This actually only applies when finding by xpath - browser.text_field(:xpath, "//input[@type='radio']")
+ # We don't need to validate the element if we built the xpath ourselves.
+ # It is also used to alter behavior of methods locating more than one type of element
+ # (e.g. text_field locates both input and textarea)
validate_element(element) if element
rescue Selenium::WebDriver::Error::NoSuchElementError
nil
end
@@ -232,11 +236,11 @@
rx_selector
end
def assert_valid_as_attribute(attribute)
- unless valid_attribute? attribute or attribute.to_s =~ /^data_.+$/
+ unless valid_attribute? attribute or attribute.to_s =~ WILDCARD_ATTRIBUTE
raise MissingWayOfFindingObjectException, "invalid attribute: #{attribute.inspect}"
end
end
def by_id
@@ -267,10 +271,10 @@
def valid_attribute?(attribute)
@valid_attributes && @valid_attributes.include?(attribute)
end
def should_use_label_element?
- @selector[:tag_name] != "option"
+ !valid_attribute?(:label)
end
def build_wd_selector(selectors)
unless selectors.values.any? { |e| e.kind_of? Regexp }
build_css(selectors) || build_xpath(selectors)