Finds elements using CSS or XPath selectors with automatic type detection, optional timeout, and configurable error handling.
async def query(
self, expression: str, timeout: int = 0, find_all: bool = False, raise_exc: bool = True
) -> Union[WebElement, list[WebElement], None]:
"""
Find element(s) using raw CSS selector or XPath expression.
Direct access using CSS or XPath syntax. Selector type automatically
determined based on expression pattern.
Args:
expression: Selector expression (CSS, XPath, ID with #, class with .).
timeout: Maximum seconds to wait for elements to appear.
find_all: If True, returns all matches; if False, first match only.
raise_exc: Whether to raise exception if no elements found.
Returns:
WebElement, list[WebElement], or None based on find_all and raise_exc.
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key