Skip to main content

A package around Selenium with an implementation of the page object model, an enhanced WebDriver and a CLI.

Project description

🌔 manen


PyPI

A package around selenium to easily construct Python objects which reflect the DOM of any webpages. Delivered with other features like an enhanced WebDriver and a resource manager.


PyPI packageDocumentationIssue tracking

manen is a package built to extend Selenium user experience. Among the core features, you can find:

  • an implementation of the page object model
  • a class which completes selenium.webdriver.remote.webdriver.WebDriver
  • some helpers to manage resources usually required by Selenium
  • a function to easily find and isolate DOM elements inside a page

This package will allow you to write more concise, flexible and powerful code compared to what you could do by using only Selenium.

📥 Installation

The package can be installed using the official package manager pip.

pip install manen

It will install the package as well as the associated CLI.

✨ Features

  • manen.finder.find allows to easily get element(s) in a HTML page. This function support several very different use cases, to help reduce your code complexity when fecthing for elements.
  • manen.resource is a module to easily interact with all the assets needed by Selenium. It allows for example to download all the drivers required to interact with web browsers.
  • manen.browser defined Browser objects, an enhanced Selenium's WebDriver.
  • manen.page_object_model is the implementation of page object model described in Selenium documentation. Thanks to that, you can wrap a HTML page inside Python class and so provides readability and stability to your code.
  • a CLI is shipped with the initial release in order to perform operations such as downloading driver executables.

🚀 Getting started

manen offers several features described in the User Guide of the documentation. We will give here a minimal example of what can be done with it; the goal will be to use Selenium to explore the PyPI page of manen and extract some information from it.

The first step is to create an instance of a Selenium WebDriver or Manen WebBrowser that will be used to browse the Internet.

In [1]: from manen.browser import ChromeBrowser

In [2]: browser = ChromeBrowser.initialize(proxy=None, headless=True)

In [3]: browser.get("https://pypi.org")

PyPI home page

We are now on the home page of PyPI. What we are going to do now is interact with the webpage using a manen Page. It will essentially use the package manen.page_object_model, that stores all the classes used to do the interface with each web element.

In [4]: import manen.page_object_model as pom
   ...:
   ...:
   ...: class HomePage(pom.Page):
   ...:     query = pom.InputElement("input[id='search']")
   ...:
   ...:
   ...: class SearchResultPage(pom.Page):
   ...:     class ResultRegions(pom.Regions):
   ...:         name = pom.TextElement("h3 span.package-snippet__name")
   ...:         version = pom.TextElement("h3 span.package-snippet__version")
   ...:         link = pom.LinkElement("a.package-snippet")
   ...:         description = pom.TextElement("p.package-snippet__description")
   ...:
   ...:     n_results = pom.IntegerElement("//*[@id='content']//form/div[1]/div[1]/p/strong")
   ...:     results = ResultRegions("ul[aria-label='Search results'] li")

The Page class is used to modelize a whole WebDriver page; all elements defined inside the class should modelize a given element on the page, identified with the selectors (XPath, CSS or else). For example, the class TextElement will extract the text from a HTML element, LinkElement will extract the href attribute from an a tag. A lot of different classes exist, all of them in charge of a special extraction; they are defined and documented in the module manen.page_object_model.

The class Region is used to modelize a sub-part of a webpage. Each region can have its own inner elements. You can have as many imbricated levels as wanted.

For example, the class HomePage defines an InputElement that do the link with the search bar. To fill a value in this search bar, you can simply assign a value to the attribute query of the instance of an HomePage, initialized with browser as argument.

In [5]: page = HomePage(browser)

In [6]: page.query = "manen"

In [7]: from manen.page_object_model import Action

In [8]: page.query = Action("submit")

Submitting the form will refer to a page with the results of our query. Let's use the class SearchResultPage to retrieve the results.

PyPI home page

In [9]: page = SearchResultPage(browser)

In [10]: page.n_results
Out[10]: 1

In [11]: page.results
Out[11]: [<__main__.SearchResultPage.ResultRegions at 0x1058e97c0>]

In [12]: print(
    ...:     f"Name: {page.results[0].name}",
    ...:     f"Description: {page.results[0].description[:80]}...",
    ...:     f"Version: {page.results[0].version}",
    ...:     f"Link: {page.results[0].link}",
    ...:     sep="\n",
    ...: )
Name: manen
Description: A package around `selenium` offering, among other features, an implementation of...
Version: 0.1.0
Link: https://pypi.org/project/manen/

Last step is to close the browser to avoid any remaining running application once we close Python.

In [13]: browser.quit()

🦾 Going further

The best way to have full knowledge of the package is to read the documentation of the project!

If you want to have the exhaustive list of improvements of the package, check the Changelog page.

Looking to contribute to fix or add new features? Just read this page, fork the official repository and start doing the modifications you want.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

manen-0.1.2.tar.gz (39.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

manen-0.1.2-py3-none-any.whl (39.8 kB view details)

Uploaded Python 3

File details

Details for the file manen-0.1.2.tar.gz.

File metadata

  • Download URL: manen-0.1.2.tar.gz
  • Upload date:
  • Size: 39.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for manen-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7786f575a50fc4d4549d52d5e57bb3f752ab21034a5214e46849e2b94e258d9f
MD5 7931704ad380b93f6d40d58dea233427
BLAKE2b-256 1bf3bdf0ffa0a3ffbf7942acac1f5dd9414282bdc5bd02a316496bb3e1bdafa6

See more details on using hashes here.

File details

Details for the file manen-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: manen-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 39.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for manen-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dc34724d7a9a0112845ca3f9fda7ec7064e0aaa98ec87caa585712d960b69bf1
MD5 230a3f025193f5fe078d2578a5abe6db
BLAKE2b-256 0a7973c2440a4c4808b1e9b8485327234fe933bcad8ada26d891e40f3ab9019b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page