Use this file to discover all available pages before exploring further.
Notte sessions can be controlled with Selenium 4’s CDP support. This allows you to use Selenium’s WebDriver API while benefiting from Notte’s cloud infrastructure, anti-detection features, and session management.
Start a Notte session and connect Selenium to it using the CDP URL:
from notte_sdk import NotteClientfrom selenium import webdriverfrom selenium.webdriver.chrome.options import Optionsclient = NotteClient()# Start Notte sessionwith client.Session() as session: # Get CDP URL cdp_url = session.cdp_url() # Configure Selenium options chrome_options = Options() chrome_options.add_experimental_option("debuggerAddress", cdp_url.replace("ws://", "").replace("wss://", "")) # Connect Selenium to Notte session driver = webdriver.Remote( command_executor=cdp_url, options=chrome_options ) # Use Selenium WebDriver API driver.get("https://example.com") print(f"Title: {driver.title}") # Take screenshot driver.save_screenshot("screenshot.png") driver.quit()
The CDP connection approach shown above works in most cases, but Selenium’s CDP support may vary by version. For more reliable connections, consider using the Remote WebDriver approach below.
A more reliable way is to use Notte’s built-in Playwright page directly:
selenium_playwright_alternative.py
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: # Access the Playwright page directly page = session.page # Use Playwright for automation page.goto("https://example.com") print(f"Title: {page.title()}")
For Python-based automation with Notte, we recommend using Playwright instead of Selenium. Notte sessions include a built-in Playwright page (session.page) that’s easier to use and better integrated.
Use Playwright-style element selection with Notte’s page:
selenium_finding_elements.py
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: page = session.page page.goto("https://example.com") # CSS selectors element = page.query_selector("div.content") # XPath (use locator with xpath) element = page.locator("xpath=//div[@class='content']") # Get text content text = page.locator("h1").inner_text() print(f"Heading: {text}") # Get attribute href = page.locator("a.link").get_attribute("href") print(f"Link: {href}")
Wait for elements to appear or conditions to be met:
selenium_waiting_elements.py
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: page = session.page page.goto("https://example.com") # Wait for element to be visible page.wait_for_selector("div.content", state="visible") # Wait for element to be hidden page.wait_for_selector("div.loading", state="hidden") # Wait for URL pattern page.click("a.next") page.wait_for_url("**/page2") # Wait with timeout page.wait_for_selector("div.result", timeout=10000) # 10 seconds
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: page = session.page page.goto("https://example.com") # Full page screenshot page.screenshot(path="screenshot.png", full_page=True) # Screenshot of specific element element = page.locator("div.content") element.screenshot(path="element.png") # Screenshot to bytes screenshot_bytes = page.screenshot()
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: page = session.page page.goto("https://example.com") # Get frame by selector frame = page.frame_locator("iframe#content") # Interact with elements inside frame frame.locator("button").click() # Get text from frame text = frame.locator("h1").inner_text() print(f"Frame heading: {text}")
Here’s a complete example using Playwright with Notte (recommended approach):
from notte_sdk import NotteClientclient = NotteClient()def automate_form(): with client.Session(headless=False) as session: page = session.page # Navigate to form page.goto("https://example.com/contact") # Fill form fields page.fill('input[name="name"]', "John Doe") page.fill('input[name="email"]', "john@example.com") page.fill('textarea[name="message"]', "Hello, this is a test message") # Select from dropdown page.select_option('select[name="topic"]', "support") # Check checkbox page.check('input[name="subscribe"]') # Submit form page.click('button[type="submit"]') # Wait for success message page.wait_for_selector("div.success") success_message = page.locator("div.success").inner_text() print(f"Success: {success_message}") # Take screenshot page.screenshot(path="success.png")automate_form()