lib/watir-webdriver/locators/element_locator.rb in watir-webdriver-0.6.11 vs lib/watir-webdriver/locators/element_locator.rb in watir-webdriver-0.7.0
- old
+ new
@@ -25,11 +25,10 @@
end
def locate
e = by_id and return e # short-circuit if :id is given
-
if @selector.size == 1
element = find_first_by_one
else
element = find_first_by_multiple
end
@@ -37,11 +36,11 @@
# This actually only applies when finding by xpath/css - 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, Selenium::WebDriver::Error::ObsoleteElementError
+ rescue Selenium::WebDriver::Error::NoSuchElementError, Selenium::WebDriver::Error::StaleElementReferenceError
nil
end
def locate_all
if @selector.size == 1
@@ -251,12 +250,10 @@
element = @wd.find_element(:id, id)
return if tag_name && !tag_name_matches?(element.tag_name.downcase, tag_name)
element
- rescue Selenium::WebDriver::Error::NoSuchElementError
- nil
end
def all_elements
@wd.find_elements(:xpath => ".//*")
end
@@ -296,29 +293,33 @@
end
def build_css(selectors)
return unless use_css?(selectors)
- css = ''
- css << (selectors.delete(:tag_name) || '')
+ if selectors.empty?
+ css = '*'
+ else
+ css = ''
+ css << (selectors.delete(:tag_name) || '')
- klass = selectors.delete(:class)
- if klass
- if klass.include? ' '
- css << %([class="#{css_escape klass}"])
- else
- css << ".#{klass}"
+ klass = selectors.delete(:class)
+ if klass
+ if klass.include? ' '
+ css << %([class="#{css_escape klass}"])
+ else
+ css << ".#{klass}"
+ end
end
- end
- href = selectors.delete(:href)
- if href
- css << %([href~="#{css_escape href}"])
- end
+ href = selectors.delete(:href)
+ if href
+ css << %([href~="#{css_escape href}"])
+ end
- selectors.each do |key, value|
- key = key.to_s.gsub("_", "-")
- css << %([#{key}="#{css_escape value}"]) # TODO: proper escaping
+ selectors.each do |key, value|
+ key = key.to_s.gsub("_", "-")
+ css << %([#{key}="#{css_escape value}"]) # TODO: proper escaping
+ end
end
[:css, css]
end