Skip to content

toggle

Toggle(browser, container)

Bases: BaseControl

Entity_Component : Button

Parameters:

Name Type Description Default
browser

The selenium webdriver

required
container

The locator of the container where the control is located in.

required
Source code in pytest_splunk_addon_ui_smartx/components/controls/toggle.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def __init__(self, browser, container):
    """
    :param browser: The selenium webdriver
    :param container: The locator of the container where the control is located in.
    """
    super().__init__(browser, container)
    self.elements.update(
        {
            "toggle_btn": Selector(
                select=container.select
                + ' [data-test="option"] :not([data-test=’screen-reader-content’])'
            ),
            "selected": Selector(
                select=container.select
                + ' [data-test="option"][aria-checked="true"] :not([data-test=’screen-reader-content’])'
            ),
        }
    )
    self.browser = browser
    self.container = container

get_value()

Returns the value of the toggle element :return: Str the text for the toggle element

Source code in pytest_splunk_addon_ui_smartx/components/controls/toggle.py
73
74
75
76
77
78
def get_value(self):
    """
    Returns the value of the toggle element
        :return: Str the text for the toggle element
    """
    return self.selected.text.strip()

select(value)

Selects the toggle specified :param value: the value to select :return: Bool if successful in selection, else raises an error

Source code in pytest_splunk_addon_ui_smartx/components/controls/toggle.py
50
51
52
53
54
55
56
57
58
59
60
61
def select(self, value):
    """
    Selects the toggle specified
        :param value: the value to select
        :return: Bool if successful in selection, else raises an error
    """
    for each in self.get_elements("toggle_btn"):
        if each.text.lower() == value.lower():
            self._wait_to_be_clickable(each)
            return True
    else:
        raise ValueError("{} not found".format(value))