# Path: saunter/po/webdriver/element.py
# class Element(object):
#     """
#     Top of the PO element tree
#     """
#     pass
# 
# Path: saunter/exceptions.py
# class ElementNotFound(SaunterExceptions):
#     def _get_message(self):
#         return self._message
# 
#     def _set_message(self, message):
#         self._message = message
#     message = property(_get_message, _set_message)


from saunter.po.webdriver.element import Element
from saunter.exceptions import ElementNotFound
# limitations under the License.
"""
=========
Attribute
=========
"""


class Attribute(Element):
    """
    Base element class for Text fields
    """
    def __init__(self, element, attribute):
        self.locator = element
        self.attribute = attribute

    def __set__(self, obj, val):
        pass

    def __get__(self, obj, cls=None):
        try:
            e = obj.driver.find_element_by_locator(self.locator)
            return e.get_attribute(self.attribute)
        except AttributeError as e:
            if str(e) == "'SeleniumWrapper' object has no attribute 'connection'":
                pass
            else:
                raise e
        except ElementNotFound as e:
            msg = "Element %s was not found. It is used in the %s page object in the %s module." % (self.locator, obj.__class__.__name__, self.__module__)

# Path: saunter/po/webdriver/element.py
# class Element(object):
#     """
#     Top of the PO element tree
#     """
#     pass
# 
# Path: saunter/exceptions.py
# class ElementNotFound(SaunterExceptions):
#     def _get_message(self):
#         return self._message
# 
#     def _set_message(self, message):
#         self._message = message
#     message = property(_get_message, _set_message)


# Path: saunter/po/webdriver/attribute.py
from saunter.po.webdriver.element import Element
from saunter.exceptions import ElementNotFound

# limitations under the License.
"""
=========
Attribute
=========
"""


class Attribute(Element):
    """
    Base element class for Text fields
    """
    def __init__(self, element, attribute):
        self.locator = element
        self.attribute = attribute

    def __set__(self, obj, val):
        pass

    def __get__(self, obj, cls=None):
        try:
            e = obj.driver.find_element_by_locator(self.locator)
            return e.get_attribute(self.attribute)
        except AttributeError as e:
            if str(e) == "'SeleniumWrapper' object has no attribute 'connection'":
                pass
            else:
                raise e
        except ElementNotFound as e:
            msg = "Element %s was not found. It is used in the %s page object in the %s module." % (self.locator, obj.__class__.__name__, self.__module__)

            raise ElementNotFound(msg)