Selenium with tab management in Python
Project description
Selenium Tabs: Enhanced Tab Management for Selenium
Simplify your web automation tasks with Selenium Tabs, a Python package that takes Selenium to the next level with streamlined tab management and additional features.
Installation
Install Selenium Tabs from PyPI with ease:
pip install seleniumtabs
Core Idea
In Selenium Tabs, a browser
contains multiple tabs
, enabling you to interact with web pages more efficiently. You can perform various actions on both Tab
and Browser
objects, making web automation a breeze.
Actions/Activities on Tab
Objects:
- Check tab status (open/closed)
- Switch to a specific tab
- Access page source, title, and headings
- Inject jQuery and select elements
- Perform actions on a specific tab (e.g., click, scroll)
- CSS selection made easy
Actions/Activities on Browser
Objects:
- Open new tabs with URLs
- Retrieve a list of open tabs
- Switch to a specific tab (first, last, or any)
- Close a tab
- Close the entire browser
Working with Driver Objects
A driver
object is available on any Tab
object,
allowing you to access the browser/driver object
and use Selenium methods when needed without making explicit switches to a specific tab.
Features
Selenium Tabs offers a range of features to enhance your web automation tasks:
- Effortless tab management
- Seamless tab switching
- Real-time tab status tracking
- Convenient tab closure
- Built-in functions for scrolling, clicking, and more
- Access to the underlying Selenium
driver
object for advanced usage
Usage
To get started with Selenium Tabs, create a Browser
object and open tabs using the open
method:
Browser
from seleniumtabs import Browser, Tab
# Create a `Browser` object, specifying the browser name (e.g., "Chrome").
# The project automatically downloads drivers.
with Browser(name="Chrome", implicit_wait=10) as browser:
google: Tab = browser.open("https://google.com")
yahoo = browser.open("https://yahoo.com")
bing = browser.open("https://bing.com")
duck_duck = browser.open("https://duckduckgo.com/")
# Scroll on the page (example)
yahoo.scroll_to_bottom()
# Working with tabs
for tab in browser.tabs:
print(tab)
print(browser.tabs)
print(browser.current_tab)
# Selecting elements with JQuery (using browserjquery package)
print(yahoo.jq("a"))
# Selecting using CSS Selectors (no JQuery needed)
for item in yahoo.css(".stream-items"):
for a in item.css("a"):
print(a, a.text)
# Some `Tab` attributes/properties
print(google.title)
print(google.url)
print(google.page_source)
# Closing a tab
browser.close_tab(bing)
# Switching to a tab
yahoo.switch()
google.switch()
# Accessing the driver object
print(google.driver.title, google.title)
TODO
- Complete documentation
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
Hashes for seleniumtabs-0.4.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 629e0f2ad70a32151f97e56aa48c7591e32b9e9ac4bfb5918b704ff4aad1301f |
|
MD5 | 1d6068c6795f8f18ce9a242c76042c05 |
|
BLAKE2b-256 | 2b8e20e0ba2cba7412c0dd3ce5a64ca740ed6ffb0fb30dfad29131b5d669c967 |