Getting Started

First Query

Run a simple example query

Run a simple query to test that everything is working as expected. In this example it is assumed that you have successfully installed the Bytebot SDK and Puppeteer. If not, please refer to the installation guide.

Make sure you import Puppeteer and the Bytebot client:

1import { BytebotClient } from '@bytebot/sdk';
2import puppeteer from "puppeteer";

Use Puppeteer to navigate to a page:

1const browser = await puppeteer.launch();
2const page = await browser.newPage();
3await page.goto('https://developer.chrome.com/');

This is only an example of how to use Puppeteer to navigate to a page. We suggest you visit the Puppeteer documentation for more information.

Instantiate a Bytebot client and execute your query:

1const bytebot = new BytebotClient({
2 apiKey: process.env.BYTEBOT_API_KEY,
3});
4
5const actions = await bytebot.extract(Attribute("The link from the 'Sign in' button"), page);

You can print the extract action:

1 console.log(actions[0]);

This example (as well as all extract prompts) resolves to a single action, but it is good practice to not make assumptions about the number of actions returned. In some circumstances you will need to handle multiple actions.

And see something like this:

${
> "xpath": "/html/body/section/devsite-header/div/div[1]/div/div/devsite-user/div/a",
> "type": "CopyAttribute",
> "attribute": "href",
>}

You can then execute the generated action on the same page reference:

1const link = await bytebot.execute(actions, page);
2console.log(link);

The console should display something like this:

$"https://developer.chrome.com/_d/signin?continue=https%3A%2F%2Fdeveloper.chrome.com%2F&prompt=select_account"

Finally, make sure you close the Puppeteer browser:

1await browser.close();

Congratulations! You have successfully run your first query using Bytebot.