17 from selenium.common.exceptions
import NoSuchElementException
18 from selenium.webdriver.support.ui
import Select
60 return select.first_selected_option.text
86 return select.first_selected_option.get_attribute(
'value')
121 self.
infoinfo(
"Verifying list '%s' has option%s [ %s ] selected."
122 % (locator, s(expected),
' | '.join(expected)))
127 if sorted(expected)
not in [sorted(labels), sorted(values)]:
128 raise AssertionError(
"List '%s' should have had selection [ %s ] "
129 "but selection was [ %s ]."
130 % (locator,
' | '.join(expected),
134 return ' | '.join(
'%s (%s)' % (label, value)
135 for label, value
in zip(labels, values))
144 self.
infoinfo(
"Verifying list '%s' has no selections." % locator)
149 raise AssertionError(
"List '%s' should have had no selection "
150 "but selection was [ %s ]."
151 % (locator, selection))
184 self.
infoinfo(
"Selecting all options from list '%s'." % locator)
186 if not select.is_multiple:
187 raise RuntimeError(
"'Select All From List' works only with "
188 "multi-selection lists.")
189 for i
in range(len(select.options)):
190 select.select_by_index(i)
207 raise ValueError(
"No indexes given.")
208 self.
infoinfo(
"Selecting options from selection list '%s' by index%s %s."
209 % (locator,
'' if len(indexes) == 1
else 'es',
212 for index
in indexes:
213 select.select_by_index(int(index))
228 raise ValueError(
"No values given.")
229 self.
infoinfo(
"Selecting options from selection list '%s' by value%s %s."
230 % (locator, s(values),
', '.join(values)))
233 select.select_by_value(value)
248 raise ValueError(
"No labels given.")
249 self.
infoinfo(
"Selecting options from selection list '%s' by label%s %s."
250 % (locator, s(labels),
', '.join(labels)))
253 select.select_by_visible_text(label)
264 self.
infoinfo(
"Unselecting all options from list '%s'." % locator)
266 if not select.is_multiple:
267 raise RuntimeError(
"Un-selecting options works only with "
268 "multi-selection lists.")
269 select.deselect_all()
282 raise ValueError(
"No indexes given.")
283 self.
infoinfo(
"Un-selecting options from selection list '%s' by index%s "
284 "%s." % (locator,
'' if len(indexes) == 1
else 'es',
287 if not select.is_multiple:
288 raise RuntimeError(
"Un-selecting options works only with "
289 "multi-selection lists.")
290 for index
in indexes:
291 select.deselect_by_index(int(index))
303 raise ValueError(
"No values given.")
304 self.
infoinfo(
"Un-selecting options from selection list '%s' by value%s "
305 "%s." % (locator, s(values),
', '.join(values)))
307 if not select.is_multiple:
308 raise RuntimeError(
"Un-selecting options works only with "
309 "multi-selection lists.")
311 select.deselect_by_value(value)
323 raise ValueError(
"No labels given.")
324 self.
infoinfo(
"Un-selecting options from selection list '%s' by label%s "
325 "%s." % (locator, s(labels),
', '.join(labels)))
327 if not select.is_multiple:
328 raise RuntimeError(
"Un-selecting options works only with "
329 "multi-selection lists.")
331 select.deselect_by_visible_text(label)
344 return [opt.text
for opt
in options]
347 return [opt.get_attribute(
'value')
for opt
in options]
def find_element(self, locator, tag=None, required=True, parent=None)
Find element matching locator.
def assert_page_not_contains(self, locator, tag=None, message=None, loglevel='TRACE')
def info(self, msg, html=False)
def assert_page_contains(self, locator, tag=None, message=None, loglevel='TRACE')
def _get_options(self, locator)
def get_selected_list_label(self, locator)
Returns label of selected option from selection list locator.
def _format_selection(self, labels, values)
def select_from_list_by_value(self, locator, *values)
Selects options from selection list locator by values.
def _get_select_list(self, locator)
def get_list_items(self, locator, values=False)
Returns all labels or values of selection list locator.
def unselect_from_list_by_index(self, locator, *indexes)
Unselects options from selection list locator by indexes.
def page_should_not_contain_list(self, locator, message=None, loglevel='TRACE')
Verifies selection list locator is not found from current page.
def get_selected_list_labels(self, locator)
Returns labels of selected options from selection list locator.
def _get_values(self, options)
def unselect_from_list_by_label(self, locator, *labels)
Unselects options from selection list locator by labels.
def select_from_list_by_label(self, locator, *labels)
Selects options from selection list locator by labels.
def _get_selected_options(self, locator)
def unselect_from_list_by_value(self, locator, *values)
Unselects options from selection list locator by values.
def get_selected_list_value(self, locator)
Returns value of selected option from selection list locator.
def select_all_from_list(self, locator)
Selects all options from multi-selection list locator.
def get_selected_list_values(self, locator)
Returns values of selected options from selection list locator.
def _get_labels(self, options)
def list_selection_should_be(self, locator, *expected)
Verifies selection list locator has expected options selected.
def select_from_list_by_index(self, locator, *indexes)
Selects options from selection list locator by indexes.
def unselect_all_from_list(self, locator)
Unselects all options from multi-selection list locator.
def list_should_have_no_selections(self, locator)
Verifies selection list locator has no options selected.
def page_should_contain_list(self, locator, message=None, loglevel='TRACE')
Verifies selection list locator is found from current page.