gummy.utils.driver_utils module¶
Utility programs for Selenium WebDriver. See 1. Installation — Selenium Python Bindings 2 documentation for more details.
-
gummy.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 gummy.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/.gummy', 'directory_upgrade': True}}
-
gummy.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
-
gummy.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 gummy.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
-
gummy.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
)
-
gummy.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
)
-
gummy.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 asLocator strategies
. Need to be selectable for generality- Parameters
driver (WebDriver) – Selenium WebDriver.
kwargs (dict) –
key
isidentifier
andval
is
-
gummy.utils.driver_utils.
download_PDF_with_driver
(url, dirname='.', verbose=True, timeout=3)[source]¶ Download PDF file with GUI driver.
- Parameters
url (str) – File URL.
dirname (str) – The directory where downloaded data will be saved.
verbose (bool) – Whether print verbose or not.
timeout (int) – Number of seconds before timing out (default=
3
)
- Returns
path/to/downloaded_file
- Return type
path (str)
-
gummy.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
)