capybara/node/actions.py
def _check_with_label(self, selector, checked, locator=None, allow_label_click=None, visible=None, wait=None,
                          **kwargs):
        """
        Args:
            selector (str): The selector for the type of element that should be checked/unchecked.
            checked (bool): Whether the element should be checked.
            locator (str, optional): Which element to check.
            allow_label_click (bool, optional): Attempt to click the label to toggle state if
                element is non-visible. Defaults to :data:`capybara.automatic_label_click`.
            visible (bool | str, optional): The desired element visibility. Defaults to
                :data:`capybara.ignore_hidden_elements`.
            wait (int | float, optional): The number of seconds to wait to check the element.
                Defaults to :data:`capybara.default_max_wait_time`.
            **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.
        """

        if allow_label_click is None:
            allow_label_click = capybara.automatic_label_click

        @self.synchronize(wait=BaseQuery.normalize_wait(wait))
        def check_with_label():
            element = None
            try:
                element = self.find(selector, locator, visible=visible, **kwargs)
                element.set(checked)
            except Exception as e:
                if not allow_label_click or not self._should_catch_error(e):
                    raise
                try:
                    if not element:
                        element = self.find(selector, locator, visible="all", **kwargs)
                    label = self.find("label", field=element, visible=True)
                    if element.checked != checked:
                        label.click()
                except Exception:
                    raise e

        check_with_label()
def _check_with_label(self, selector, checked, locator=None, allow_label_click=None, visible=None, wait=None,
                          **kwargs):
        """
        Args:
            selector (str): The selector for the type of element that should be checked/unchecked.
            checked (bool): Whether the element should be checked.
            locator (str, optional): Which element to check.
            allow_label_click (bool, optional): Attempt to click the label to toggle state if
                element is non-visible. Defaults to :data:`capybara.automatic_label_click`.
            visible (bool | str, optional): The desired element visibility. Defaults to
                :data:`capybara.ignore_hidden_elements`.
            wait (int | float, optional): The number of seconds to wait to check the element.
                Defaults to :data:`capybara.default_max_wait_time`.
            **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.
        """

        if allow_label_click is None:
            allow_label_click = capybara.automatic_label_click

        @self.synchronize(wait=BaseQuery.normalize_wait(wait))
        def check_with_label():
            element = None
            try:
                element = self.find(selector, locator, visible=visible, **kwargs)
                element.set(checked)
            except Exception as e:
                if not allow_label_click or not self._should_catch_error(e):
                    raise
                try:
                    if not element:
                        element = self.find(selector, locator, visible="all", **kwargs)
                    label = self.find("label", field=element, visible=True)
                    if element.checked != checked:
                        label.click()
                except Exception:
                    raise e

        check_with_label()
Args:
            selector (str): The selector for the type of element that should be checked/unchecked.
            checked (bool): Whether the element should be checked.
            locator (str, optional): Which element to check.
            allow_label_click (bool, optional): Attempt to click the label to toggle state if
                element is non-visible. Defaults to :data:`capybara.automatic_label_click`.
            visible (bool | str, optional): The desired element visibility. Defaults to
                :data:`capybara.ignore_hidden_elements`.
            wait (int | float, optional): The number of seconds to wait to check the element.
                Defaults to :data:`capybara.default_max_wait_time`.
            **kwargs: Arbitrary keyword arguments for :class:`SelectorQuery`.