mahler

Submodules

Classes

Controller

Controller class to interact with a browser window.

Element

Remote browser object API.

Window

Remote browser interactive API.

Fingerprint

Fingerprint class to hold browser signature.

Package Contents

class mahler.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

class mahler.Element(native_element: Any, parent: Element | None = None)

Bases: Protocol

Remote browser object API.

Parameters:
  • native_element (Any) – The native element API for the underlying automation suite.

  • parent (Element | None, optional) – The parent. Defaults to None.

property parent: Element | None

The parent element this was selected from, if any.

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

Select all child elements of this node 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) Element | None

Select the first child element of this node 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

click() None

Click on this element.

content() str

Return the text content of this element.

type_on(text: str, delay: float = 0) None

Emulate typing on this element.

Parameters:
  • text (str) – Text to type.

  • delay (float, optional) – Time in seconds to wait between keys. Defaults to 0.

class mahler.Window(model: Literal['chrome', 'firefox'], headless: bool = True, enable_javascript: bool = True, fingerprint: mahler.fingerprint.Fingerprint | None = None)

Bases: Protocol

Remote browser interactive API.

Parameters:
  • 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.

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.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.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

class mahler.Fingerprint

Fingerprint class to hold browser signature.

headers: dict | None
user_agent: str | None