Super easy to use selenium wrapper
Project description
🥙 donerkebab 🥙
> A super easy to use, beginner friendly [selenium](https://pypi.org/project/selenium/) wrapper$ pip install donerkebab
Usage
1. Download the driver for your browser
2. Place it in a PATH directory
This might be /usr/bin or the directory as your python script
# Also available for Firefox, Edge, Safari and Opera
from donerkebab import ChromeDriver
# Get an instance of the browser window
# You can easily start it in headless mode too
driver = ChromeDriver(headless=False)
driver.open('https://duckduckgo.com/')
# Browser will wait at max 10 seconds until element is found
driver.set_timeout(10)
# You can find elements by their CSS selectors
input_box = driver.get_element('input#search_form_input_homepage')
# Uses classic selenium element functions
input_box.send_keys('Do pigs fly?')
driver.sleep(2)
submit_button = driver.get_element('input#search_button_homepage')
# Perform the search
submit_button.click()
# Get the container of all the result links
results_container = driver.get_element('div.results--main')
# Get all the links inside the container with a class of 'results__a'
results = driver.get_elements_in_parent(results_container, 'a.result__a')
# Print all the links
print("🔎 Results for 'Do pigs fly?' 🔎")
for result in results:
# get title and href attribute (the link adress) for every result
print(result.text + ' -> ' + result.get_attribute('href'))
driver.quit()
API
Driver init options
driver = FirefoxDriver(log=True, executable_path=None,headless=False, page_load_strategy='normal'):
headless -> Hides the window and runs the browser in the background. Really usefull
log -> Enable or disable logging
executable_path -> The full path to executable driver. If left null the it will look at the PATH variable to find the driver.
page_load_strategy -> Take a look at the [official docs](https://www.selenium.dev/documentation/webdriver/capabilities/shared/#pageloadstrategy)
Locating elements
Css selectors
donerkebab always uses css selectors for locating elements. Some examples:
inputelement with type inputdiv > inputelement that is the direct child of inputinput.searchelement with a class of 'search'input#main_buttonelement with an id of 'main_button'a[href='https://google.com']link element with a href attribute
Definately check out more advanced css selectors. They come in really handy
Locator methods
driver.get_element(css_selector)
driver.get_elements(css_selector)
driver.get_element_in_parent(parent_element, css_selector)
driver.get_elements_in_parent(parent_element, css_selector)
driver.get_element_by_xpath(xpath)
driver.is_element_present(css_selector) # Searches for element without any timeout
# Tries the first selector, if none element is found, tries the alternate selector
# Great for having backup selectors for elements that might change
driver.get_element_multiple_attempts(selector1, selector2, selector3...)
# Returns the active element
driver.active_element
# Scrolls that element into view
driver.scroll_to_element(element)
# Waits until an alert is present, and returns that alert
driver.get_alert()
Driver methods
open(url)
Opens the url and waits until the page loads. Url must start with https:// or http://
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file donerkebab-0.0.2.tar.gz.
File metadata
- Download URL: donerkebab-0.0.2.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b083d157719c773585a98de593553d5fcd05cf6b8041e31b6cdb614069f03361
|
|
| MD5 |
c27697f25ed8c6069fd0f8dc144d6588
|
|
| BLAKE2b-256 |
2136430e243260d8787509898f8f38edaab90b1d6ebd6e21e4f1a4ccf465bd53
|
File details
Details for the file donerkebab-0.0.2-py2-none-any.whl.
File metadata
- Download URL: donerkebab-0.0.2-py2-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3a0574fa247f316d14fce1872debdf30f3361d6e61fd31a4567b62fa08dfbd5
|
|
| MD5 |
4b98699a966f98f3b1615978d1f95dff
|
|
| BLAKE2b-256 |
bcfc4d5622baf3e44e74da3b440ea0934eca5af65e8412d71ccdd38e63327146
|