manen.browser#
Classes which enrich selenium.webdriver.remote.webdriver.WebDriver
.
- class manen.browser.BraveBrowser(executable_path='chromedriver', port=0, options: Options | None = None, service_args=None, desired_capabilities=None, service_log_path=None, chrome_options=None, service: Service | None = None, keep_alive=None)[source]#
Bases:
ChromeBrowser
Enhanced ChromeWebDriver that will launch a Brave browser instead of Google Chrome.
- BINARIES = {'Darwin': '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'}#
- class manen.browser.BrowserMixin[source]#
Bases:
WebDriverProtocol
Mixin to enrich
selenium.webdriver.remote.webdriver.WebDriver
with a set of features intended to ease the way to work with such an instance.- property are_versions_compatible#
Property telling you if the version of the used driver is compatible with the one of the browser.
- property browser_version: Version#
Version of the browser in used.
- click_with_js(element: SeleniumElement)[source]#
Click on an element using a JavaScript script. Can be useful if you want to click on an element outside the current frame.
- property cookies#
Cookies associated to the current domain.
- property current_platform#
Platform (OS information) on which the driver runs.
- property driver_version: Version#
Version of the driver in used.
- find(selector: str | List[str], **kwargs)[source]#
This method is basically the same as
find()
but with the driver instance as default value for the argumentinside
and True as default value formany
argument. See the documentation offind()
for more information of what we can do with this method.
- highlight(selector: str | List[str], **kwargs)[source]#
Highlight an element in the current webpage by drawing a black frame around this element. The element will be retrieved using the
find
method and then framed by updating the CSS properties of the retrieved element.
- lookup(*args, **kwargs) Any [source]#
This method is exactly as the method
find
but it will always return a default value if an element cannot be found (this defaul value is by default None. To keep it simple, this is thefind
method which never raises an exception if a selection method returns nothing!- Parameters:
*args – postional arguments sent directly as arguments of the method
find
**kwargs – keyword arguments sent directly as arguments of the method
find
- Returns:
Outputs of
find()
- Return type:
Any
- scroll(n_repeat: int = 3, wait: int = 1, direction: str = 'DOWN', with_js: bool = False)[source]#
Perform a scroll action on the page.
- Parameters:
n_repeat (int, optional) – Number of scroll to perform. Defaults to 3.
wait (int, optional) – Number of seconds to wait between each scroll. Defaults to 1.
direction (str, optional) – scroll up or down (can only be
UP
orDOWN
, case insensitive). Defaults to “DOWN”.with_js (bool, optional) – perform the action with a JavaScript script instead of scrolling by pressing the Key DOWN or UP. Defaults to False.
- Raises:
ValueError – Raised if direction (once lowercased) is not UP or DOWN
- class manen.browser.ChromeBrowser(executable_path='chromedriver', port=0, options: Options | None = None, service_args=None, desired_capabilities=None, service_log_path=None, chrome_options=None, service: Service | None = None, keep_alive=None)[source]#
Bases:
BrowserMixin
,WebDriver
Wrapper around Selenium ChromeWebDriver providing additional methods in order to give more abilities and flexibilities when controlling the browser. For example, it defines a method
find
to easily retrieve elements,highlight
to put an emphasis on elements or cookies property. Go check the documentation of methods inherited fromBrowserMixin
for further information.- BINARIES = {'Darwin': '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', 'Linux': 'google-chrome'}#
- classmethod initialize(proxy: str | None = None, headless: bool = False, driver_path: str | None = None, window_size: Tuple[int, int] | None = None)[source]#
Class method to easily launch an enhanced new driver based on the browser Chrome. Here you can specify directly if the browser should run headless or not, if a proxy should be used and many more options.
- Parameters:
proxy (str, optional) – proxy to use. Defaults to
None
.headless (bool, optional) – whether the browser should be launched headless. Defaults to
False
.driver_path (str, optional) – path of the driver program to use. If None, manen will use functions defined in the package
resources
to find one (and download one if needed). Defaults toNone
.window_size (Tuple[int, int], optional) – size of the browser window to be launched. Defaults to
None
.
- Returns:
An enhanced Chrome driver
- Return type:
WebDriver