def _check_with_label(self, selector, checked, locator=None, allow_label_click=None, visible=None, wait=None,<EOL>**kwargs):
if allow_label_click is None:<EOL><INDENT>allow_label_click = capybara.automatic_label_click<EOL><DEDENT>@self.synchronize(wait=BaseQuery.normalize_wait(wait))<EOL>def check_with_label():<EOL><INDENT>element = None<EOL>try:<EOL><INDENT>element = self.find(selector, locator, visible=visible, **kwargs)<EOL>element.set(checked)<EOL><DEDENT>except Exception as e:<EOL><INDENT>if not allow_label_click or not self._should_catch_error(e):<EOL><INDENT>raise<EOL><DEDENT>try:<EOL><INDENT>if not element:<EOL><INDENT>element = self.find(selector, locator, visible="<STR_LIT:all>", **kwargs)<EOL><DEDENT>label = self.find("<STR_LIT:label>", field=element, visible=True)<EOL>if element.checked != checked:<EOL><INDENT>label.click()<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>raise e<EOL><DEDENT><DEDENT><DEDENT>check_with_label()<EOL>
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`.