Usage

There are three submodules you will look into for different utils:

Drivers

Provides shortcuts for drivers creation.

Available tools are:

Core

Provides core functionality of the package. All of the function from this module directy access the webdriver and its state.

Available tools are:

Helpers

Provides helpers for writing things using Selenium.

Available tools are:

About core.SeleniumDriver

selenium_extensions.core.SeleniumDriver provides all of the tools available in selenium_extensions.core in a single class. It also can create driver by calling super() from child class and then use it for all the selenium_extensions.core functionality, so you don’t need to provide driver as the first argument to SeleniumDriver’s methods. Let’s look at some code:

from selenium.webdriver.common.by import By
from selenium_extensions.core import SeleniumDriver


class MyBot(SeleniumDriver):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def goto_google(self):
        self.driver.get('https://google.com')
        searchbox_locator = (By.ID, 'lst-ib')
        # core.wait_for_element_to_be_present is now available as self.wait_for_element_to_be_present
        self.wait_for_element_to_be_present(searchbox_locator)
        # core.populate_text_field is now available as self.populate_text_field
        self.populate_text_field(searchbox_locator, 'query')


bot = MyBot(browser='chrome', executable_path='/usr/bin/chromedriver', run_headless=True, load_images=False)
bot.goto_google()
bot.shut_down()  # core.shut_down() is now available as self.shut_down()

Another option, if you don’t enjoy OOP style, would be we just to initialize SeleniumDriver and use its driver attribute to do whatever you want. So the code above could look like this:

from selenium.webdriver.common.by import By
from selenium_extensions.core import SeleniumDriver


bot = SeleniumDriver(browser='chrome', executable_path='/usr/bin/chromedriver',
                     run_headless=False, load_images=False)
bot.driver.get('https://google.com')
searchbox_locator = (By.ID, 'lst-ib')
bot.wait_for_element_to_be_present(searchbox_locator)
bot.populate_text_field(searchbox_locator, 'query')
bot.shut_down()