pycharmers.utils.driver_utils module

Utility programs for Selenium WebDriver. See 1. Installation — Selenium Python Bindings 2 documentation for more details.

pycharmers.utils.driver_utils.get_chrome_options(browser=False)[source]

Get default chrome options.

Parameters

browser (bool) – Whether you want to run Chrome with GUI browser. (default= False )

Examples

>>> from pycharmers.utils import get_chrome_options
>>> # browser == False (default)
>>> op = get_chrome_options(browser=False)
>>> op.arguments
['--no-sandbox',
'--ignore-certificate-errors',
'--disable-dev-shm-usage',
'--headless']
>>> op.experimental_options
{}
>>> # browser == True
>>> op = get_chrome_options(browser=True)
>>> op.arguments
['--no-sandbox',
'--ignore-certificate-errors',
'--disable-dev-shm-usage',
'--kiosk-printing']
>>> op.experimental_options
{'prefs': {'profile.default_content_settings.popups': 1,
'download.default_directory': '/Users/iwasakishuto/.pycharmers',
'directory_upgrade': True}}
pycharmers.utils.driver_utils.get_driver(driver_type='local', chrome_options=None, browser=False, selenium_port='4444')[source]

Get a driver that works in your current environment.

Parameters
  • driver_type (str) – driver type. (default= DRIVER_TYPE)

  • chrome_options (ChromeOptions) – Instance of ChromeOptions. If not specify, use get_chrome_options() to get default options.

  • browser (bool) – Whether you want to run Chrome with GUI browser. (default= False )

  • selenium_port (str) – selenium port number. This will be used when you run on Docker

pycharmers.utils.driver_utils.try_find_element(driver, by, identifier, timeout=3, verbose=True)[source]

Find an element given a By strategy and locator.

Wrap with try_wrapper to handle the error so that the programs does not stop in a series of processes.

Parameters
  • driver (WebDriver) – Selenium WebDriver.

  • by (str) – Locator strategies. See 4. Locating Elements — Selenium Python Bindings 2 documentation

  • identifier (str) – Identifier to find the element

  • timeout (int) – Number of seconds before timing out (default= 3)

  • verbose (bool) – Whether you want to print output or not. (default= True )

Examples

>>> from pycharmers.utils import get_driver, try_find_element
>>> with get_driver() as driver:
...     driver.get("https://www.google.com/")
...     e = try_find_element(driver=driver, by="tag name", identifier="img")
Succeeded to locate element with tag name=img
pycharmers.utils.driver_utils.try_find_element_send_keys(driver, by=None, identifier=None, values=(), target=None, timeout=3, verbose=True)[source]

Find an element given a By strategy and locator, and Simulates typing into the element.

Wrap with try_wrapper to handle the error so that the programs does not stop in a series of processes.

Parameters
  • driver (WebDriver) – Selenium WebDriver.

  • by (str) –

    Locator strategies. See 4. Locating Elements — Selenium Python Bindings 2 documentation

  • identifier (str) – Identifier to find the element

  • values (tuple) – A string for typing, or setting form fields. For setting file inputs, this could be a local file path.

  • target (WebElement) – Represents a DOM element. (If you already find element)

  • timeout (int) – Number of seconds before timing out (default= 3)

  • verbose (bool) – Whether you want to print output or not. (default= True )

pycharmers.utils.driver_utils.try_find_element_click(driver, by=None, identifier=None, target=None, timeout=3, verbose=True)[source]

Find an element given a By strategy and locator, and Clicks the element.

Wrap with try_wrapper to handle the error so that the programs does not stop in a series of processes.

Parameters
  • driver (WebDriver) – Selenium WebDriver.

  • by (str) –

    Locator strategies. See 4. Locating Elements — Selenium Python Bindings 2 documentation

  • identifier (str) – Identifier to find the element

  • target (WebElement) – Represents a DOM element. (If you already find element)

  • timeout (int) – Number of seconds before timing out (default= 3)

  • verbose (bool) – Whether you want to print output or not. (default= True )

pycharmers.utils.driver_utils.click()[source]

function for differentiation

pycharmers.utils.driver_utils.pass_forms(driver, **kwargs)[source]

Pass through forms.

You can check the example in passthrough_base

Todo

Currently, only "id" is supported as Locator strategies. Need to be selectable for generality

Parameters
  • driver (WebDriver) – Selenium WebDriver.

  • kwargs (dict) – key is identifier and val is

pycharmers.utils.driver_utils.wait_until_all_elements(driver, timeout, verbose=True)[source]

Wait until all elements visible.

Parameters
  • driver (WebDriver) – Selenium WebDriver.

  • timeout (int) – Number of seconds before timing out (default= 3)

  • verbose (bool) – Whether you want to print output or not. (default= True )

pycharmers.utils.driver_utils.scrollDown(driver, verbose=True)[source]

Scroll down to the bottom of the page.

Parameters
  • driver (WebDriver) – Selenium WebDriver.

  • verbose (bool) – Whether you want to print output or not. (default= True )