# ---------------------------------------------------------------------------------
# RadioBox Wait Conditions
#
# These are a collection of classes for WebDriverWait specific to radio boxes
#
# --------------------------------------------------------------------------------

from accelarobotkeywords.config.seleniumsettings import SeleniumSettings


class RadioBoxCheck(object):
    """Condition to check/select a radio box"""
    def __init__(self, locator):
        self.locator_type = locator.locator_type
        self.locator_value = locator.locator_value

    def __call__(self, driver):
        try:
            driver.implicitly_wait(1)
            element = driver.find_element(self.locator_type, self.locator_value)
            element.click()
            return element.is_selected()
        except Exception:
            return False
        finally:
            driver.implicitly_wait(SeleniumSettings.get_implicit_wait())
