old_contents: class Identifier:
      @staticmethod
      def id(element):
          return "id=" + element.get_attribute("id")
  
      @staticmethod
      def class_name(element):
          return "class=" + element.get_attribute("class")
  
      @staticmethod
      def name(element):
          return "name=" + element.get_attribute("name")
  
      @staticmethod
      def text(element):
          return "xpath=.//*[.='%s')]" % element.get_text()
  
new_contents: class Identifier:
      id = staticmethod(lambda element: "id=" + element.get_attribute("id"))
  
      class_name = staticmethod(lambda element: "class=" + element.get_attribute("class"))
  
      name = staticmethod(lambda element: "name=" + element.get_attribute("name"))
  
      text = staticmethod(lambda element: "xpath=.//*[.='%s')]" % element.get_text())
  
subject: use lambda instead of define method.