class Capybara::Selector

def locate_field(xpath, locator, **_options)

def locate_field(xpath, locator, **_options)
  return xpath if locator.nil?
  locate_xpath = xpath # Need to save original xpath for the label wrap
  locator = locator.to_s
  attr_matchers = [XPath.attr(:id) == locator,
                   XPath.attr(:name) == locator,
                   XPath.attr(:placeholder) == locator,
                   XPath.attr(:id) == XPath.anywhere(:label)[XPath.string.n.is(locator)].attr(:for)].reduce(:|)
  attr_matchers |= XPath.attr(:'aria-label').is(locator) if enable_aria_label
  attr_matchers |= XPath.attr(test_id) == locator if test_id
  locate_xpath = locate_xpath[attr_matchers]
  locate_xpath + XPath.descendant(:label)[XPath.string.n.is(locator)].descendant(xpath)
end