capybara/node/matchers.py
def assert_selector(self, *args, **kwargs):
        """
        Asserts that a given selector is on the page or a descendant of the current node. ::

            page.assert_selector("p#foo")

        By default it will check if the expression occurs at least once, but a different number can
        be specified. ::

            page.assert_selector("p.foo", count=4)

        This will check if the expression occurs exactly 4 times. See :meth:`find_all` for other
        available result size options.

        If a ``count`` of 0 is specified, it will behave like :meth:`assert_no_selector`; however,
        use of that method is preferred over this one.

        It also accepts all options that :meth:`find_all` accepts, such as ``text`` and
        ``visible``. ::

            page.assert_selector("li", text="Horse", visible=True)

        ``assert_selector`` can also accept XPath expressions generated by the ``xpath-py``
        package::

            from xpath import dsl as x

            page.assert_selector("xpath", x.descendant("p"))

        Args:
            *args: Variable length argument list for :class:`SelectorQuery`.
            **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

        Returns:
            True

        Raises:
            ExpectationNotMet: The given selector did not match.
        """

        query = SelectorQuery(*args, **kwargs)

        @self.synchronize(wait=query.wait)
        def assert_selector():
            result = query.resolve_for(self)

            if not (result.matches_count and
                    (len(result) > 0 or expects_none(query.options))):
                raise ExpectationNotMet(result.failure_message)

            return True

        return assert_selector()
def assert_selector(self, *args, **kwargs):
        """
        Asserts that a given selector is on the page or a descendant of the current node. ::

            page.assert_selector("p#foo")

        By default it will check if the expression occurs at least once, but a different number can
        be specified. ::

            page.assert_selector("p.foo", count=4)

        This will check if the expression occurs exactly 4 times. See :meth:`find_all` for other
        available result size options.

        If a ``count`` of 0 is specified, it will behave like :meth:`assert_no_selector`; however,
        use of that method is preferred over this one.

        It also accepts all options that :meth:`find_all` accepts, such as ``text`` and
        ``visible``. ::

            page.assert_selector("li", text="Horse", visible=True)

        ``assert_selector`` can also accept XPath expressions generated by the ``xpath-py``
        package::

            from xpath import dsl as x

            page.assert_selector("xpath", x.descendant("p"))

        Args:
            *args: Variable length argument list for :class:`SelectorQuery`.
            **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

        Returns:
            True

        Raises:
            ExpectationNotMet: The given selector did not match.
        """

        query = SelectorQuery(*args, **kwargs)

        @self.synchronize(wait=query.wait)
        def assert_selector():
            result = query.resolve_for(self)

            if not (result.matches_count and
                    (len(result) > 0 or expects_none(query.options))):
                raise ExpectationNotMet(result.failure_message)

            return True

        return assert_selector()
def assert_selector ( self , * args , * * kwargs ) : query = SelectorQuery ( * args , * * kwargs ) @ self . synchronize ( wait = query . wait ) def assert_selector ( ) : result = query . resolve_for ( self ) if not ( result . matches_count and ( len ( result ) > 0 or expects_none ( query . options ) ) ) : raise ExpectationNotMet ( result . failure_message ) return True return assert_selector ( )
Asserts that a given selector is on the page or a descendant of the current node. ::

            page.assert_selector("p#foo")

        By default it will check if the expression occurs at least once, but a different number can
        be specified. ::

            page.assert_selector("p.foo", count=4)

        This will check if the expression occurs exactly 4 times. See :meth:`find_all` for other
        available result size options.

        If a ``count`` of 0 is specified, it will behave like :meth:`assert_no_selector`; however,
        use of that method is preferred over this one.

        It also accepts all options that :meth:`find_all` accepts, such as ``text`` and
        ``visible``. ::

            page.assert_selector("li", text="Horse", visible=True)

        ``assert_selector`` can also accept XPath expressions generated by the ``xpath-py``
        package::

            from xpath import dsl as x

            page.assert_selector("xpath", x.descendant("p"))

        Args:
            *args: Variable length argument list for :class:`SelectorQuery`.
            **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.

        Returns:
            True

        Raises:
            ExpectationNotMet: The given selector did not match.
Asserts that a given selector is on the page or a descendant of the current node . ::