Skip to content

multi_select

MultiSelect(browser, container)

Bases: BaseControl

Entity-Component: Multiselect A dropdown which can select more than one values

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/multi_select.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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)

    root_selector = container.select + ' [data-test="multiselect"]'
    self.elements.update({"root": Selector(select=root_selector)})

    self.elements.update(
        {
            "selected": Selector(
                # changes w.r.t. splunk-ui 4.30.0
                select=root_selector
                + ' [data-test="selected-option"] div[data-test="label"]'
            ),
            """
            Click on selected element deselects it
            """
            "deselect": Selector(
                # changes w.r.t. splunk-ui 4.30.0
                select=root_selector
                + ' [data-test="selected-option"] div[data-test="label"]'
            ),
            "input": Selector(select=root_selector + ' [data-test="textbox"]'),
        }
    )

clear_text()

Clears the search box value in the multiselect field

Source code in pytest_splunk_addon_ui_smartx/components/controls/multi_select.py
67
68
69
70
71
def clear_text(self):
    """
    Clears the search box value in the multiselect field
    """
    self.input.clear()

deselect(value)

Remove an item from selected list. :param value: the value to deselect :return: Bool returns true if deselect was successful, else raises an exception

Source code in pytest_splunk_addon_ui_smartx/components/controls/multi_select.py
125
126
127
128
129
130
131
132
133
134
135
136
137
def deselect(self, value):
    """
    Remove an item from selected list.
        :param value: the value to deselect
        :return: Bool returns true if deselect was successful, else raises an exception
    """
    for each in self.get_child_elements("selected"):
        if each.text.strip().lower() == value.lower():
            each.click()
            self.wait_for("root")
            return True
    else:
        raise ValueError("{} not found in select list".format(value))

deselect_all()

Remove all items from selected list.

Source code in pytest_splunk_addon_ui_smartx/components/controls/multi_select.py
139
140
141
142
143
144
def deselect_all(self):
    """
    Remove all items from selected list.
    """
    for each in self.get_values():
        self.deselect(each)

get_list_count()

Gets the total count of the Multiselect list

Source code in pytest_splunk_addon_ui_smartx/components/controls/multi_select.py
173
174
175
176
177
def get_list_count(self):
    """
    Gets the total count of the Multiselect list
    """
    return len(list(self.list_of_values()))

get_values()

get list selected values :return: List of values selected within the multi-select

Source code in pytest_splunk_addon_ui_smartx/components/controls/multi_select.py
146
147
148
149
150
151
def get_values(self):
    """
    get list selected values
        :return: List of values selected within the multi-select
    """
    return [each.text.strip() for each in self.get_child_elements("selected")]

list_of_values()

Get list of possible values to select from dropdown :return: List of options within the multi-select dropdown

Source code in pytest_splunk_addon_ui_smartx/components/controls/multi_select.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
def list_of_values(self):
    """
    Get list of possible values to select from dropdown
        :return: List of options within the multi-select dropdown
    """
    self.wait_for("root")
    list_of_values = []
    self.input.click()
    popover_id = "#" + self.root.get_attribute("data-test-popover-id")
    self.elements.update(
        {
            "values": Selector(
                select=popover_id + ' [data-test="option"] [data-test="label"]'
            )
        }
    )
    for each in self.get_elements("values"):
        list_of_values.append(each.text.strip())
    return list_of_values

search(value)

search with the multiselect input :param value: string value to search

Source code in pytest_splunk_addon_ui_smartx/components/controls/multi_select.py
60
61
62
63
64
65
def search(self, value):
    """
    search with the multiselect input
        :param value: string value to search
    """
    self.input.send_keys(value)

search_get_list(value)

search with the multiselect input and return the list :param value: string value to search :return: list of values

Source code in pytest_splunk_addon_ui_smartx/components/controls/multi_select.py
73
74
75
76
77
78
79
80
81
82
83
def search_get_list(self, value):
    """
    search with the multiselect input and return the list
        :param value: string value to search
        :return: list of values
    """
    self.search(value)
    self.wait_for_search_list()
    searched_values = list(self._list_visible_values())
    self.input.send_keys(Keys.ESCAPE)
    return searched_values

select(value)

select a single value :param value: the value to select :return: Bool returns true if selection was successful, else raises an exception

Source code in pytest_splunk_addon_ui_smartx/components/controls/multi_select.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
def select(self, value):
    """
    select a single value
        :param value: the value to select
        :return: Bool returns true if selection was successful, else raises an exception
    """
    try:
        try:
            self.input.click()
        except ElementClickInterceptedException:
            self.label_text.click()
            self.input.click()

    except:
        raise Exception("dropdown not found")

    popover_id = "#" + self.root.get_attribute("data-test-popover-id")
    self.elements.update(
        {"values": Selector(select=popover_id + ' [data-test="option"]')}
    )
    for each in self.get_elements("values"):
        if each.text.strip().lower() == value.lower():
            try:
                each.click()
            except ElementClickInterceptedException:
                self.elements.update(
                    {
                        value.lower(): Selector(
                            select=popover_id
                            + f' [data-test="option"][data-test-value="{value.lower()}"]'
                        )
                    }
                )
                self.hover_over_element(f"{value.lower()}")
                each.click()
            self.wait_for("input")
            return True
    else:
        raise ValueError("{} not found in select list".format(value))

wait_for_search_list()

Wait for Multiselect search to populate

Source code in pytest_splunk_addon_ui_smartx/components/controls/multi_select.py
207
208
209
210
211
212
213
214
215
216
217
def wait_for_search_list(self):
    """
    Wait for Multiselect search to populate
    """

    def _wait_for_search_list(driver):
        return len(list(self._list_visible_values())) > 0

    self.wait_for(
        _wait_for_search_list, msg="No values found in Multiselect search"
    )

wait_for_values()

Wait for dynamic values to load in Mulitple select

Source code in pytest_splunk_addon_ui_smartx/components/controls/multi_select.py
197
198
199
200
201
202
203
204
205
def wait_for_values(self):
    """
    Wait for dynamic values to load in Mulitple select
    """

    def _wait_for_values(driver):
        return self.get_list_count() > 0

    self.wait_for(_wait_for_values, msg="No values found in Multiselect")