Package: manen
🌔  manenA package aroundseleniumto easily construct Python objects which reflect the DOM of any webpages.Delivered with other features like an enhanced WebDriver and a resource manager.PyPI package・Documentation・Issue trackingmanenis a package built to extend Selenium user experience.
Among the core features, you can find:an implementation of thepage object modela class which completesselenium.webdriver.remote.webdriver.WebDriversome helpers to manage resources usually required by Seleniuma function to easily find and isolate DOM elements inside a pageThis package will allow you to write more concise, flexible and powerful code compared to
what you could do by using only Selenium.📥  InstallationThe package can be installed using the official package managerpip.pipinstallmanenIt will install the package as well as the associated CLI.✨ Featuresmanen.finder.findallows 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.resourceis 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.browserdefinedBrowserobjects, an enhanced Selenium'sWebDriver.manen.page_object_modelis 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 startedmanenoffers several features described in theUser Guideof 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 ofmanenand extract some information from it.The first step is to create an instance of a SeleniumWebDriveror ManenWebBrowserthat will be
used to browse the Internet.In[1]:frommanen.browserimportChromeBrowserIn[2]:browser=ChromeBrowser.initialize(proxy=None,headless=True)In[3]:browser.get("https://pypi.org")We are now on the home page of PyPI. What we are going to do now is interact with the webpage
using a manenPage. It will essentially use the packagemanen.page_object_model, that
stores all the classes used to do the interface with each web element.In[4]:importmanen.page_object_modelaspom...:...:...:classHomePage(pom.Page):...:query=pom.InputElement("input[id='search']")...:...:...:classSearchResultPage(pom.Page):...:classResultRegions(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")ThePageclass 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 classTextElementwill extract the text from a HTML element,LinkElementwill
extract thehrefattribute from anatag. A lot of different classes exist, all of them in charge
of a special extraction; they are defined and documented in the modulemanen.page_object_model.The classRegionis 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 classHomePagedefines anInputElementthat do the link with the search bar.
To fill a value in this search bar, you can simply assign a value to the attributequeryof
the instance of anHomePage, initialized withbrowseras argument.In[5]:page=HomePage(browser)In[6]:page.query="manen"In[7]:frommanen.page_object_modelimportActionIn[8]:page.query=Action("submit")Submitting the form will refer to a page with the results of our query. Let's use the classSearchResultPageto retrieve the results.In[9]:page=SearchResultPage(browser)In[10]:page.n_resultsOut[10]:1In[11]:page.resultsOut[11]:[<__main__.SearchResultPage.ResultRegionsat0x1058e97c0>]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:manenDescription:Apackagearound`selenium`offering,amongotherfeatures,animplementationof...Version:0.1.0Link: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 furtherThe best way to have full knowledge of the package is to readthe documentation of the project!If you want to have the exhaustive list of improvements of the package, check theChangelogpage.Looking to contribute to fix or add new features? Just readthis page,
fork the official repository and start doing the modifications you want.