manen.browser

Classes which inherits from WebDriver, and add useful methods for driver interactions.

class manen.browser.BrowserMixin[source]

Bases: WebDriverProtocol

Mixin to enhance WebDriver with a set of features intended to ease the way to work with a WebDriver instance.

property browser_version: Version

Version of the browser

click_with_js(element: WebElement)[source]

Click on an element using JavaScript (useful to click on an element outside the current frame).

property cookies

Cookies associated to the current domain

property current_platform

Current platform of the webdriver

property driver_version: Version

Version of the driver

find(selector: str | list[str], **kwargs)[source]

Find elements matching selectors using find(), with the driver instance as scope for the search. Returns all elements by default.

Parameters:
Raises:

ElementNotFound – Raised if no default value is specified and no element matching the selector(s) has been found.

Returns:

Outputs of find()

Return type:

Any

highlight(selector: str | list[str], **kwargs)[source]

Highlight an element in the current page by drawing a black frame around it.

Parameters:
  • selector (str | list[str]) – selector(s) used to find the element.

  • **kwargs – Keyword arguments sent to find method

property is_browser_compatible_with_driver

Is the browser version compatible with the driver version?

lookup(*args, **kwargs) Any[source]

Same as the method find() with the difference that this method never raises error. If the element is not found, it returns a default value (None by default).

Parameters:
  • *args – positional arguments passed to find()

  • *kwargs – keyword arguments passed to find()

Returns:

Outputs of find()

Return type:

Any

scroll(n: int = 1, wait: int = 0, direction: ScrollDirection = ScrollDirection.DOWN, with_js: bool = False)[source]

Scroll the page, in a given direction.

Parameters:
  • n (int, optional) – Number of scroll to perform. Defaults to 1.

  • wait (int, optional) – Number of seconds to wait between each scroll. Defaults to 0.

  • direction (str, optional) – scroll up or down (can only be UP or DOWN). Defaults to DOWN.

  • with_js (bool, optional) – perform the action with a JavaScript script instead of scrolling by pressing the keys down or up. Defaults to False.

Raises:

ValueError – Raised if direction is not UP or DOWN

class manen.browser.ChromeBrowser(options: Options | None = None, service: Service | None = None, keep_alive: bool = True)[source]

Bases: BrowserMixin, WebDriver

Wrapper around Selenium ChromeWebDriver providing methods to improve its operability.

classmethod initialize(options: Options | None = None, service: Service | None = None, driver_path: str | None = None, headless_mode: HeadlessMode | None = None, proxy: str | None = None, window_size: tuple[int, int] | None = None)[source]

Launch an enhanced web driver for the browser Chrome.

Parameters:
  • options (ChromeOptions, optional) – Options to configure the driver. Defaults to None.

  • service (ChromeService, optional) – Service to configure the driver. Defaults to None.

Returns:

An enhanced Chrome driver

Return type:

WebDriver

class manen.browser.HeadlessMode(value)[source]

Bases: str, Enum

An enumeration.

NEW = 'new'
OLD = 'old'
class manen.browser.ScrollDirection(value)[source]

Bases: str, Enum

An enumeration.

DOWN = 'DOWN'
UP = 'UP'