# Path: webdriverwrapper/wrapper.py
# class _WebElementWrapper(_WebdriverBaseWrapper, WebElement):
#     """
#     Class wrapping :py:class:`selenium.WebElement <selenium.webdriver.remote.webelement.WebElement>`.
#     """
# 
#     def __new__(cls, webelement):
#         instance = super().__new__(cls)
#         instance.__dict__.update(webelement.__dict__)
#         return instance
# 
#     def __init__(self, webelement):
#         # Nothing to do because whole __dict__ of original WebElement was
#         # copied during creation of instance.
#         pass
# 
#     @property
#     def _driver(self):
#         """
#         Returns always driver, not element. Use it when you need driver
#         and variable can be driver or element.
#         """
#         return self._parent
# 
#     @property
#     def current_url(self):
#         """
#         Accessing :py:attr:`~selenium.webdriver.remote.webdriver.WebDriver.current_url`
#         also on elements.
#         """
#         try:
#             current_url = self._driver.current_url
#         except Exception:  # pylint: disable=broad-except
#             current_url = 'unknown'
#         finally:
#             return current_url
# 
#     @property
#     def html(self):
#         """
#         Returns ``innerHTML``.
# 
#         .. versionadded:: 2.2
#         """
#         self.get_attribute('innerHTML')
# 
#     def clear(self):
#         # Just add some context when calling clear fails.
#         try:
#             return super().clear()
#         except (
#                 selenium_exc.StaleElementReferenceException,
#                 selenium_exc.InvalidElementStateException,
#                 selenium_exc.ElementNotVisibleException,
#                 selenium_exc.ElementNotSelectableException,
#         ) as exc:
#             raise exc.__class__('Problem clearing element at {}.'.format(self.current_url))
# 
#     def download_file(self):
#         """
#         With WebDriver you can't check status code or headers. For this you have
#         to make classic request. But web pages needs cookies and data from forms
#         and by this it gets pretty ugly. You can easily use this method.
# 
#         It can handle downloading of page/file by link or any type of form.
# 
#         Returns :py:obj:`~webdriverwrapper.download._Download` instance.
#         """
#         return DownloadFile(self)
# 
# Path: webdriverwrapper/exceptions.py
# def _create_exception_msg(
#         id_=None, class_name=None, name=None, tag_name=None,
#         parent_id=None, parent_class_name=None, parent_name=None, parent_tag_name=None,
#         text=None, xpath=None, css_selector=None, url=None,
#         driver=None,
# ):
#     elm_text = _create_exception_msg_tag(
#         id_, class_name, name, tag_name,
#         parent_id, parent_class_name, parent_name, parent_tag_name,
#         text, xpath, css_selector,
#     )
#     msg = 'No element {} found'.format(elm_text)
#     if url:
#         msg += ' at {}'.format(url)
# 
#     suggest = _get_suggestion(driver, id_, class_name, tag_name)
#     if suggest:
#         msg += ' {}'.format(suggest)
# 
#     return msg


from selenium.common.exceptions import WebDriverException, NoSuchElementException
from selenium.webdriver.common.keys import Keys
from webdriverwrapper.wrapper import _WebElementWrapper
from webdriverwrapper.exceptions import _create_exception_msg

    def convert_value(self, value):
        if not isinstance(value, (list, tuple)):
            return self._convert_value_to_string(value)

        values = []
        for item in value:
            values.append(self._convert_value_to_string(item))
        return values

    # pylint: disable=no-self-use
    def _convert_value_to_string(self, value):
        if isinstance(value, bool):
            value = int(value)
        elif value is None:
            value = ''
        return str(value)

    def fill_out(self, value, skip_reset):
        tag_name, elm_type = self.analyze_element()
        method_name = ('fill_%s_%s' % (tag_name, elm_type)).replace('-', '')
        getattr(self, method_name, self.fill_common)(value, skip_reset)

    def analyze_element(self):
        elms = self.form_elm.get_elms(name=self.elm_name)
        for elm in elms:
            elm_type = elm.get_attribute('type')
            if elm_type == 'hidden':
                continue
            return elm.tag_name, elm_type

# Path: webdriverwrapper/wrapper.py
# class _WebElementWrapper(_WebdriverBaseWrapper, WebElement):
#     """
#     Class wrapping :py:class:`selenium.WebElement <selenium.webdriver.remote.webelement.WebElement>`.
#     """
# 
#     def __new__(cls, webelement):
#         instance = super().__new__(cls)
#         instance.__dict__.update(webelement.__dict__)
#         return instance
# 
#     def __init__(self, webelement):
#         # Nothing to do because whole __dict__ of original WebElement was
#         # copied during creation of instance.
#         pass
# 
#     @property
#     def _driver(self):
#         """
#         Returns always driver, not element. Use it when you need driver
#         and variable can be driver or element.
#         """
#         return self._parent
# 
#     @property
#     def current_url(self):
#         """
#         Accessing :py:attr:`~selenium.webdriver.remote.webdriver.WebDriver.current_url`
#         also on elements.
#         """
#         try:
#             current_url = self._driver.current_url
#         except Exception:  # pylint: disable=broad-except
#             current_url = 'unknown'
#         finally:
#             return current_url
# 
#     @property
#     def html(self):
#         """
#         Returns ``innerHTML``.
# 
#         .. versionadded:: 2.2
#         """
#         self.get_attribute('innerHTML')
# 
#     def clear(self):
#         # Just add some context when calling clear fails.
#         try:
#             return super().clear()
#         except (
#                 selenium_exc.StaleElementReferenceException,
#                 selenium_exc.InvalidElementStateException,
#                 selenium_exc.ElementNotVisibleException,
#                 selenium_exc.ElementNotSelectableException,
#         ) as exc:
#             raise exc.__class__('Problem clearing element at {}.'.format(self.current_url))
# 
#     def download_file(self):
#         """
#         With WebDriver you can't check status code or headers. For this you have
#         to make classic request. But web pages needs cookies and data from forms
#         and by this it gets pretty ugly. You can easily use this method.
# 
#         It can handle downloading of page/file by link or any type of form.
# 
#         Returns :py:obj:`~webdriverwrapper.download._Download` instance.
#         """
#         return DownloadFile(self)
# 
# Path: webdriverwrapper/exceptions.py
# def _create_exception_msg(
#         id_=None, class_name=None, name=None, tag_name=None,
#         parent_id=None, parent_class_name=None, parent_name=None, parent_tag_name=None,
#         text=None, xpath=None, css_selector=None, url=None,
#         driver=None,
# ):
#     elm_text = _create_exception_msg_tag(
#         id_, class_name, name, tag_name,
#         parent_id, parent_class_name, parent_name, parent_tag_name,
#         text, xpath, css_selector,
#     )
#     msg = 'No element {} found'.format(elm_text)
#     if url:
#         msg += ' at {}'.format(url)
# 
#     suggest = _get_suggestion(driver, id_, class_name, tag_name)
#     if suggest:
#         msg += ' {}'.format(suggest)
# 
#     return msg


# Path: webdriverwrapper/forms.py
from selenium.common.exceptions import WebDriverException, NoSuchElementException
from selenium.webdriver.common.keys import Keys
from webdriverwrapper.wrapper import _WebElementWrapper
from webdriverwrapper.exceptions import _create_exception_msg


    def convert_value(self, value):
        if not isinstance(value, (list, tuple)):
            return self._convert_value_to_string(value)

        values = []
        for item in value:
            values.append(self._convert_value_to_string(item))
        return values

    # pylint: disable=no-self-use
    def _convert_value_to_string(self, value):
        if isinstance(value, bool):
            value = int(value)
        elif value is None:
            value = ''
        return str(value)

    def fill_out(self, value, skip_reset):
        tag_name, elm_type = self.analyze_element()
        method_name = ('fill_%s_%s' % (tag_name, elm_type)).replace('-', '')
        getattr(self, method_name, self.fill_common)(value, skip_reset)

    def analyze_element(self):
        elms = self.form_elm.get_elms(name=self.elm_name)
        for elm in elms:
            elm_type = elm.get_attribute('type')
            if elm_type == 'hidden':
                continue
            return elm.tag_name, elm_type

        raise NoSuchElementException(_create_exception_msg(name=self.elm_name))