MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / assert_elements

Method assert_elements

seleniumbase/fixtures/base_case.py:10603–10663  ·  view source on GitHub ↗

Similar to self.assert_element(), but can assert multiple elements. The input is a list of elements. Optional kwargs include "by" and "timeout" (used by all selectors). Raises an exception if any of the elements are not visible. Allows flexible inputs (Eg. Multiple ar

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

10601 return True
10602
10603 def assert_elements(self, *args, **kwargs):
10604 """Similar to self.assert_element(), but can assert multiple elements.
10605 The input is a list of elements.
10606 Optional kwargs include "by" and "timeout" (used by all selectors).
10607 Raises an exception if any of the elements are not visible.
10608 Allows flexible inputs (Eg. Multiple args or a list of args)
10609 Examples:
10610 self.assert_elements("h1", "h2", "h3")
10611 OR
10612 self.assert_elements(["h1", "h2", "h3"]) """
10613 self.__check_scope()
10614 selectors = []
10615 timeout = None
10616 by = By.CSS_SELECTOR
10617 for kwarg in kwargs:
10618 if kwarg == "timeout":
10619 timeout = kwargs["timeout"]
10620 elif kwarg == "by":
10621 by = kwargs["by"]
10622 elif kwarg == "selector" or kwarg == "selectors":
10623 selector = kwargs["selector"]
10624 if isinstance(selector, str):
10625 selectors.append(selector)
10626 elif isinstance(selector, list):
10627 selectors_list = selector
10628 for selector in selectors_list:
10629 if isinstance(selector, str):
10630 selectors.append(selector)
10631 else:
10632 raise Exception('Unknown kwarg: "%s"!' % kwarg)
10633 if not timeout:
10634 timeout = settings.SMALL_TIMEOUT
10635 if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
10636 timeout = self.__get_new_timeout(timeout)
10637 for arg in args:
10638 if isinstance(arg, list):
10639 for selector in arg:
10640 if isinstance(selector, str):
10641 selectors.append(selector)
10642 elif isinstance(arg, str):
10643 selectors.append(arg)
10644 for selector in selectors:
10645 if self.__is_shadow_selector(selector):
10646 self.__assert_shadow_element_visible(selector)
10647 continue
10648 self.wait_for_element_visible(selector, by=by, timeout=timeout)
10649 if self.demo_mode:
10650 selector, by = self.__recalculate_selector(selector, by)
10651 a_t = "ASSERT"
10652 if self._language != "English":
10653 from seleniumbase.fixtures.words import SD
10654
10655 a_t = SD.translate_assert(self._language)
10656 messenger_post = "<b>%s %s</b>: %s" % (
10657 a_t, by.upper(), selector
10658 )
10659 self.__highlight_with_assert_success(
10660 messenger_post, selector, by

Callers 3

assert_elementMethod · 0.95

Calls 8

__check_scopeMethod · 0.95
__get_new_timeoutMethod · 0.95
__is_shadow_selectorMethod · 0.95
translate_assertMethod · 0.80

Tested by 1