class Watir::Locators::Row::SelectorBuilder::XPath

Public Instance Methods

build(selector, scope_tag_name) click to toggle source
# File lib/watir/locators/row/selector_builder/xpath.rb, line 6
def build(selector, scope_tag_name)
  return super(selector) if selector.key?(:adjacent)

  index = selector.delete(:index)

  super(selector)
  common_string = @built.delete(:xpath)
  expressions = generate_expressions(scope_tag_name)
  expressions.map! { |e| "#{e}#{common_string}" } unless common_string.empty?

  xpath = expressions.join(' | ').to_s

  @built[:xpath] = index ? add_index(xpath, index) : xpath
  @built
end

Private Instance Methods

generate_expressions(scope_tag_name) click to toggle source
# File lib/watir/locators/row/selector_builder/xpath.rb, line 37
def generate_expressions(scope_tag_name)
  if %w[tbody tfoot thead].include?(scope_tag_name)
    ["./*[local-name()='tr']"]
  else
    ["./*[local-name()='tr']",
     "./*[local-name()='tbody']/*[local-name()='tr']",
     "./*[local-name()='thead']/*[local-name()='tr']",
     "./*[local-name()='tfoot']/*[local-name()='tr']"]
  end
end
start_string() click to toggle source
# File lib/watir/locators/row/selector_builder/xpath.rb, line 24
def start_string
  @adjacent ? './' : ''
end
text_string() click to toggle source
# File lib/watir/locators/row/selector_builder/xpath.rb, line 28
def text_string
  return super if @adjacent

  # Can not directly locate a Row with Text because all text is in the Cells;
  # needs to use Locator#locate_matching_elements
  @built[:text] = @selector.delete(:text) if @selector.key?(:text)
  ''
end