Overview
The Tab class is the controlling mechanism for a browser target. For most users, a “target” is a tab, but it can also be an iframe, service worker, or background script. When you open a new window usingbrowser.get(..., new_window=True), your URL opens in a new window, which is represented as a Tab. When you browse to another page, the Tab object remains the same.
Properties
url
The current URL of the tab.closed
Whether the tab is closed.target_id
The unique target ID.type_
The target type (usually “page”).browser
The parent Browser instance.inspector_url
The DevTools inspector URL for this tab.Navigation methods
get()
Navigate to a URL.The URL to navigate to.
Open in a new tab.
Open in a new window.
The tab that navigated (or the new tab if created).
back()
Navigate back in history.forward()
Navigate forward in history.reload()
Reload the page.Whether to ignore cache and re-download resources.
JavaScript to execute on page load.
Finding elements
find()
Find a single element by text content.Text to search for (including script contents).
When True, returns the element with the most similar text length. When False, returns the first match.
Return the containing element instead of the text node.
Timeout in seconds.
The found element.
find_all()
Find multiple elements by text.Text to search for.
Timeout in seconds.
List of matching elements.
select()
Find a single element by CSS selector.CSS selector (e.g.,
a[href], button[class*=close]).Timeout in seconds.
The found element.
select_all()
Find multiple elements by CSS selector.CSS selector.
Timeout in seconds.
Include results from iframes.
List of matching elements.
xpath()
Find elements by XPath.XPath query string.
Timeout in seconds.
List of matching elements (empty list if none found).
query_selector()
Equivalent to JavaScript’sdocument.querySelector().
query_selector_all()
Equivalent to JavaScript’sdocument.querySelectorAll().
wait_for()
Wait for an element to appear.CSS selector to wait for.
Text content to wait for.
Timeout in seconds.
The element once it appears.
JavaScript execution
evaluate()
Execute JavaScript in the page context.JavaScript code to execute.
Wait for promises to resolve.
Return the value directly instead of a RemoteObject.
The result of the JavaScript execution.
js_dumps()
Dump a JavaScript object with its properties and values.Name of the JavaScript object to dump (e.g.,
"window").Return as a dict or CDP objects.
The serialized object.
Page interaction
scroll_down()
Scroll down the page.Percentage to scroll (25 = quarter page, 100 = full page).
Scroll speed in pixels per second.
scroll_up()
Scroll up the page.Percentage to scroll.
Scroll speed in pixels per second.
get_content()
Get the page HTML source.The page HTML.
Window management
maximize()
Maximize the window.minimize()
Minimize the window.fullscreen()
Set window to fullscreen.set_window_size()
Set window size and position.Pixels from left edge.
Pixels from top edge.
Window width in pixels.
Window height in pixels.
get_window()
Get window ID and bounds.Tuple of (WindowID, Bounds).
activate()
Activate (focus) this tab.bring_to_front()
Alias foractivate().
close()
Close the tab.Screenshots and downloads
screenshot_b64()
Capture a screenshot as base64.Image format:
"jpeg" or "png".Capture entire page instead of viewport.
Base64-encoded image data.
save_screenshot()
Save a screenshot to file.File path. If “auto”, generates filename from URL.
Image format:
"jpeg" or "png".Capture entire page.
Path to saved screenshot.
download_file()
Download a file from a URL.URL of the file to download.
Filename for the downloaded file. If None, uses URL filename.
save_snapshot()
Save a page snapshot in MHTML format.Path to save the snapshot.
Network expectations
expect_request()
Create a request expectation for a URL pattern.URL pattern to match.
RequestExpectation instance.
expect_response()
Create a response expectation for a URL pattern.URL pattern to match.
ResponseExpectation instance.
expect_download()
Create a download expectation.DownloadExpectation instance.
intercept()
Intercept network requests.URL pattern to match.
Stage to intercept (e.g., request, response).
Resource type (e.g., Document, Script, Image).
Interception instance.
Utilities
wait_for_ready_state()
Wait for the page to reach a ready state.Ready state to wait for:
"loading", "interactive", or "complete".Timeout in seconds.
True if ready state reached.
open_external_inspector()
Open the DevTools inspector in your system browser.inspector_open()
Open the inspector in a new browser window.send()
Send a CDP command.Chrome DevTools Protocol command.
Command result.
Examples
Basic navigation and element interaction
Execute JavaScript
Screenshots
Wait for elements
Window management
Notes
- Tab objects persist across page navigations
- Always use
awaitwhen calling Tab methods - Use
await tabto update references and let the script “breathe” - For text searches, use
find()withbest_match=Truefor better results - Screenshots work best after ensuring the page is fully loaded