module RWebSpec::ElementLocator

Constants

BUTTON_VALID_TYPES
CHECK_BOX_TYPES
FILE_FIELD_TYPES
HIDDEN_TYPES
RADIO_TYPES
TEXT_FILED_TYPES

TextField, TextArea

Public Instance Methods

attribute_expression(selectors) click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 74
def attribute_expression(selectors)
  selectors.map do |key, val|
    if val.kind_of?(Array)
      "(" + val.map { |v| equal_pair(key, v) }.join(" or ") + ")"
    else
      equal_pair(key, val)
    end
  end.join(" and ")
end
button_elements() click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 5
def button_elements
  find_elements(:xpath, ".//button | .//input[#{attribute_expression :type => BUTTON_VALID_TYPES}]")
end
check_box_elements(how, what, opts = []) click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 10
def check_box_elements(how, what, opts = [])
  find_elements(:xpath, ".//input[#{attribute_expression :type => CHECK_BOX_TYPES}]")
end
equal_pair(key, value) click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 52
def equal_pair(key, value)
  # we assume :label means a corresponding label element, not the attribute

  if key == :label && should_use_label_element?
    "@id=//label[normalize-space()='#{value}']/@for"
  else
    "#{lhs_for(key)}='#{value}'"
  end
end
file_field_elements() click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 34
def file_field_elements
  find_elements(:xpath, ".//input[#{attribute_expression :type => FILE_FIELD_TYPES}]")
end
find_by_tag(tag) click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 44
def find_by_tag(tag)
  find_elements(:tag_name, tag)
end
hidden_elements() click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 39
def hidden_elements
  find_elements(:xpath, ".//input[#{attribute_expression :type => HIDDEN_TYPES}]")
end
lhs_for(key) click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 61
def lhs_for(key)
  case key
  when :text, 'text'
    'normalize-space()'
  when :href
    # TODO: change this behaviour?

    'normalize-space(@href)'
  else
    "@#{key.to_s.gsub("_", "-")}"
  end
end
radio_elements(how, what, opts = []) click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 15
def radio_elements(how, what, opts = [])
  find_elements(:xpath, ".//input[#{attribute_expression :type => RADIO_TYPES}]")
end
select_elements(how, what, opts = []) click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 19
def select_elements(how, what, opts = [])
  find_elements(:xpath, ".//input[#{attribute_expression :type => RADIO_TYPES}]")
end
should_use_label_element?() click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 48
def should_use_label_element?
  @selector[:tag_name] != "option" rescue false
end
text_area_elements() click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 29
def text_area_elements
  find_elements(:xpath, ".//textarea")
end
text_field_elements() click to toggle source
# File lib/rwebspec-webdriver/element_locator.rb, line 25
def text_field_elements
  find_elements(:xpath, ".//input[#{attribute_expression :type => TEXT_FILED_TYPES}]")
end