Skip to content

stagehandvsselenium

MIT 183 14 22,012
2.8 million (month) Oct 29 2024 3.2.1(2026-04-10 21:10:37 ago)
34,072 30 198 Apache-2.0
Apr 25 2008 54.1 million (month) 4.43.0(2026-04-10 06:47:01 ago)

Stagehand is an AI-powered browser automation framework for JavaScript and TypeScript, built by Browserbase. It provides a simple API for controlling browsers using natural language instructions, powered by large language models.

Stagehand offers three core primitives:

  • act() Performs actions on the page described in natural language. For example, page.act("click the login button") will find and click the appropriate element.
  • extract() Extracts structured data from the page based on a natural language description and an optional schema definition.
  • observe() Analyzes the current page state and returns actionable elements and their descriptions, useful for understanding what actions are available on a page.

Key features include:

  • TypeScript-first Built with full TypeScript support and type-safe extraction using Zod schemas.
  • Multiple LLM providers Works with OpenAI, Anthropic, and other LLM providers for powering the AI.
  • Vision and DOM analysis Combines visual screenshot analysis with DOM inspection for robust element identification.
  • Playwright integration Uses Playwright as the browser automation backend, giving access to the full Playwright API alongside AI-powered actions.
  • Browserbase cloud Optionally integrates with Browserbase cloud for managed browser infrastructure.

Stagehand is particularly suited for automating complex web workflows where traditional selectors would be fragile, such as interacting with frequently changing UIs or scraping sites with dynamic layouts.

Selenium is a Python package that allows developers to automate web browsers. It provides a way for developers to interact with web browsers programmatically, simulating user interactions such as clicking links, filling out forms, and navigating between pages. Selenium can be used to automate tasks such as web scraping, testing web applications, and automating repetitive tasks on websites.

Selenium is built on top of WebDriver, which is a browser automation API that allows Selenium to interact with web browsers. Selenium supports a wide variety of web browsers, including Chrome, Firefox, Safari, and Internet Explorer.

One of the main advantages of Selenium is that it can be used with many different programming languages, not only Python, and it also supports different platforms.

The package also provide a set of APIs that allows you to interact with web pages, you can locate elements, interact with them, get their properties and interact with javascript, you can use the APIs to automate the browser and interact with web pages in the same way a human user would.

Selenium is widely used in web scraping, web testing, and other automation tasks because it allows developers to automate web browsers in a way that is very similar to how a human user would interact with the browser.

Overall, Selenium is a powerful and versatile tool for automating web browsers and is widely used in web scraping, web testing, and other automation tasks.

Highlights


ai-powerednatural-languagetypescript

Example Use


```javascript import { Stagehand } from '@browserbasehq/stagehand'; import { z } from 'zod'; const stagehand = new Stagehand({ env: 'LOCAL', // or 'BROWSERBASE' for cloud browsers modelName: 'gpt-4o', }); await stagehand.init(); const page = stagehand.page; // Navigate to a page await page.goto('https://news.ycombinator.com'); // Use natural language to interact await page.act('click on the "new" link in the navigation'); // Extract structured data with a schema const stories = await page.extract({ instruction: 'Extract the top 5 story titles and their point counts', schema: z.object({ stories: z.array(z.object({ title: z.string(), points: z.number(), })), }), }); console.log(stories); // Observe available actions on the page const actions = await page.observe('What actions can I take on this page?'); console.log(actions); await stagehand.close(); ```
```python from selenium import webdriver # Create an instance of the webdriver driver = webdriver.Firefox() # Navigate to a website driver.get("http://www.example.com") # Find an element by its id element = driver.find_element_by_id("example-id") # Interact with the element element.click() # Find an element by its name element = driver.find_element_by_name("example-name") # Fill an input form element.send_keys("example text") # Find and click a button driver.find_element_by_xpath("//button[text()='Search']").click() # Wait for the page to load driver.implicitly_wait(10) # Get the page title print(driver.title) # Close the browser driver.close() ```

Alternatives / Similar


Was this page helpful?