mahler.controller

Attributes

ENGINE_TO_WINDOW_CLS

Classes

Controller

Controller class to interact with a browser window.

Module Contents

mahler.controller.ENGINE_TO_WINDOW_CLS
class mahler.controller.Controller(engine: Literal['playwright', 'selenium'], model: Literal['chrome', 'firefox'], headless: bool = True, enable_javascript: bool = True, fingerprint: mahler.fingerprint.Fingerprint | None = None, user_agent: str | None = None)

Controller class to interact with a browser window.

Parameters:
  • engine (Literal["playwright", "selenium"]) – Automation suite to use.

  • model (Literal["chrome", "firefox"]) – Browser type.

  • headless (bool, optional) – Run in headless mode. Defaults to True.

  • enable_javascript (bool, optional) – Enable JavaScript in browser. Defaults to True.

  • fingerprint (Fingerprint | None, optional) – Browser fingerprint to apply, if any. Defaults to None.

  • user_agent (str | None, optional) – User agent to apply to browser, if any. Defaults to None.

Raises:

ValueError – Raised if an invalid engine is given.

property engine: str

Automation suite being used.

property model: str

Browser type.

property window: mahler.protocols.Window

Current window object for the controller.

goto(url: str, timeout: float | None = None) None

Navigate to a URL.

Parameters:
  • url (str) – URL to visit.

  • timeout (float | None, optional) – Time in seconds to let load. Defaults to None.

query_selector_all(selector: str) list[mahler.protocols.Element] | None

Select all elements on the page that match the given selector.

Parameters:

selector (str) – A CSS or XPATH selector string.

Returns:

A list of elements found, if any.

Otherwise, None.

Return type:

list[Element] | None

query_selector(selector: str) mahler.protocols.Element | None

Select the first element on the page that matches the given selector.

Parameters:

selector (str) – A CSS or XPATH selector string.

Returns:

Found element, if any. Otherwise, None.

Return type:

list[Element] | None