capybara.queries package¶
Submodules¶
capybara.queries.ancestor_query module¶
-
class
capybara.queries.ancestor_query.
AncestorQuery
(selector, locator=None, between=None, count=None, exact=None, exact_text=None, filter=None, match=None, maximum=None, minimum=None, text=None, visible=None, wait=None, **filter_options)[source]¶ Bases:
capybara.queries.selector_query.SelectorQuery
-
description
¶ str – A long description of this query.
-
resolve_for
(node, exact=None)[source]¶ Resolves this query relative to the given node.
Parameters: - node (node.Base) – The node relative to which this query should be resolved.
- exact (bool, optional) – Whether to exactly match text.
Returns: A list of elements matched by this query.
Return type: list[Element]
-
capybara.queries.base_query module¶
-
class
capybara.queries.base_query.
BaseQuery
[source]¶ Bases:
object
-
static
normalize_wait
(wait)[source]¶ Returns the number of seconds to wait.
Parameters: wait (int | float | bool, optional) – The desired wait time in seconds, or False
to disable waiting. Defaults tocapybara.default_max_wait_time
.Returns: The number of seconds to wait. Return type: int
-
static
capybara.queries.current_path_query module¶
-
class
capybara.queries.current_path_query.
CurrentPathQuery
(expected_path, url=False, only_path=False)[source]¶ Bases:
object
Queries the current path.
Parameters: - expected_path (str | RegexObject) – The expected path.
- url (bool, optional) – Whether the complete URL should match. Defaults to False.
- only_path (bool, optional) – Whether only the path (excluding the query string) should match. Defaults to False.
-
failure_message
¶ str – A description of this query’s failure.
-
negative_failure_message
¶ str – A description of this query’s negative failure.
capybara.queries.selector_query module¶
-
class
capybara.queries.selector_query.
SelectorQuery
(selector, locator=None, between=None, count=None, exact=None, exact_text=None, filter=None, match=None, maximum=None, minimum=None, text=None, visible=None, wait=None, **filter_options)[source]¶ Bases:
capybara.queries.base_query.BaseQuery
Queries for elements using a selector.
If no locator is provided and the given selector is not a valid selector, the first argument is assumed to be the locator and the default selector will be used.
Parameters: - selector (str) – The name of the selector to use.
- locator (str) – An identifying string to use to locate desired elements.
- between (Iterable[int], optional) – A range of acceptable counts.
- count (int, optional) – The number of times the selector should match. Defaults to any number of times greater than zero.
- exact (bool, optional) – Whether to exactly match the locator string. Defaults to
capybara.exact
. - exact_text (bool | str, optional) – Whether to exactly match the text, or the exact text to match. Defaults to False.
- filter (Callable[[Element], bool], optional) – A function for filtering results.
- match (str, optional) – The matching strategy to use. Defaults to
capybara.match
. - maximum (int, optional) – The maximum number of times the selector should match. Defaults to infinite.
- minimum (int, optional) – The minimum number of times the selector should match. Defaults to 1.
- text (str | RegexObject, optional) – Text that should be contained in matched elements.
- visible (bool | str, optional) – The desired element visibility. Defaults to
capybara.ignore_hidden_elements
. - wait (bool | int | float, optional) – Whether and how long to wait for synchronization.
Defaults to
capybara.default_max_wait_time
. - **filter_options – Arbitrary keyword arguments for the selector’s filters.
-
description
¶ str – A long description of this query.
-
exact
¶ bool – Whether to exactly match the locator string.
-
exact_text
¶
-
kwargs
¶ Dict[str, Any] – The keyword arguments with which this query was initialized.
-
label
¶ str – A short description of the selector.
-
match
¶ str – The matching strategy to use.
-
matches_filters
(node)[source]¶ Returns whether the given node matches all filters.
Parameters: node (Element) – The node to evaluate. Returns: Whether the given node matches. Return type: bool
-
name
¶ str – The name of selector.
-
resolve_for
(node, exact=None)[source]¶ Resolves this query relative to the given node.
Parameters: - node (node.Base) – The node relative to which this query should be resolved.
- exact (bool, optional) – Whether to exactly match text.
Returns: A list of elements matched by this query.
Return type: list[Element]
-
visible
¶ str – The desired element visibility.
-
wait
¶ int | float – How long to wait for synchronization.
capybara.queries.sibling_query module¶
-
class
capybara.queries.sibling_query.
SiblingQuery
(selector, locator=None, between=None, count=None, exact=None, exact_text=None, filter=None, match=None, maximum=None, minimum=None, text=None, visible=None, wait=None, **filter_options)[source]¶ Bases:
capybara.queries.selector_query.SelectorQuery
-
description
¶ str – A long description of this query.
-
resolve_for
(node, exact=None)[source]¶ Resolves this query relative to the given node.
Parameters: - node (node.Base) – The node relative to which this query should be resolved.
- exact (bool, optional) – Whether to exactly match text.
Returns: A list of elements matched by this query.
Return type: list[Element]
-
capybara.queries.style_query module¶
-
class
capybara.queries.style_query.
StyleQuery
(expected_styles, wait=None)[source]¶ Bases:
capybara.queries.base_query.BaseQuery
Queries for computed style values of a node.
Parameters: - expected_styles (Dict[str, str]) – The expected style names and values.
- wait (bool | int | float, optional) – Whether and how long to wait for synchronization.
Defaults to
capybara.default_max_wait_time
.
-
failure_message
¶ str – A message describing the query failure.
-
resolves_for
(node)[source]¶ Resolves this query relative to the given node.
Parameters: node (node.Base) – The node to be evaluated. Returns: The number of matches found. Return type: int
-
wait
¶ int | float – How long to wait for synchronization.
capybara.queries.text_query module¶
-
class
capybara.queries.text_query.
TextQuery
(query_type, expected_text=None, between=None, count=None, exact_text=False, maximum=None, minimum=None, wait=None)[source]¶ Bases:
capybara.queries.base_query.BaseQuery
Queries for text content in a node.
If only one argument is provided, it will be assumed to be
expected_text
.Parameters: - query_type (str, optional) – One of “visible” or “all”. Defaults to “visible”.
- expected_text (str | RegexObject) – The desired text.
- between (Iterable[int], optional) – A range of acceptable counts.
- count (int, optional) – The number of times the text should match. Defaults to any number of times greater than zero.
- exact_text (bool, optional) – Whether to match the text exactly. Defaults to False.
- maximum (int, optional) – The maximum number of times the selector should match. Defaults to infinite.
- minimum (int, optional) – The minimum number of times the selector should match. Defaults to 1.
- wait (bool | int | float, optional) – Whether and how long to wait for synchronization.
Defaults to
capybara.default_max_wait_time
.
-
description
¶
-
failure_message
¶ str – A message describing the query failure.
-
negative_failure_message
¶ str – A message describing the negative query failure.
-
resolve_for
(node)[source]¶ Resolves this query relative to the given node.
Parameters: node (node.Base) – The node to be evaluated. Returns: The number of matches found. Return type: int
-
wait
¶ int | float – How long to wait for synchronization.
capybara.queries.title_query module¶
-
class
capybara.queries.title_query.
TitleQuery
(expected_title, exact=False, wait=None)[source]¶ Bases:
capybara.queries.base_query.BaseQuery
Queries the title content of a node.
Parameters: - expected_title (str | RegexObject) – The desired title.
- exact (bool, optional) – Whether the text should match exactly. Defaults to False.
- wait (bool | int | float, optional) – Whether and how long to wait for synchronization.
Defaults to
capybara.default_max_wait_time
.
-
failure_message
¶ str – A message describing the query failure.
-
negative_failure_message
¶ str – A message describing the negative query failure.
-
resolves_for
(node)[source]¶ Resolves this query relative to the given node.
Parameters: node (node.Document) – The node to be evaluated. Returns: Whether the given node matches this query. Return type: bool
-
wait
¶ int | float – How long to wait for synchronization.