> ## Documentation Index
> Fetch the complete documentation index at: https://docs.testdriver.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Navigate with the address bar and scroll

> Navigate by typing in Chrome's address bar, then scroll and assert on the result.

This test types a URL into Chrome's address bar, scrolls down, and asserts that the heading is out of view.

## Watch it run

[https://api-test.testdriver.ai/api/v1/testdriver/testcase/6ad6b600022b6043aeec2bf0/replay](https://api-test.testdriver.ai/api/v1/testdriver/testcase/6ad6b600022b6043aeec2bf0/replay)

## The test

```javascript title="navigate-and-scroll.test.mjs" theme={null}
import { describe, expect, it } from "vitest";
import { TestDriver } from "testdriverai/vitest/hooks";

describe("Scroll Keyboard Test", () => {
  it("should navigate to webhamster.com and scroll with keyboard", async (context) => {
    const testdriver = TestDriver(context);
    await testdriver.provision.chrome({ url: 'http://testdriver-sandbox.vercel.app/login' });

    // Navigate to https://www.webhamster.com/ through the address bar
    await testdriver.focusApplication("Google Chrome");
    const urlBar = await testdriver.find(
      "the URL in the omnibox", {zoom: true}
    );
    await urlBar.click();
    await testdriver.pressKeys(["ctrl", "a"]);
    await testdriver.type("https://www.webhamster.com/");
    await testdriver.pressKeys(["enter"]);

    // Click the page so it has focus, then scroll down
    const heading = await testdriver.find(
      "The Hamster Dance, large heading at top of page",
    );
    await heading.click();
    await testdriver.scroll("down", { amount: 1000 });

    // Assert the page is scrolled down
    const result = await testdriver.assert("The text 'The Hamster Dance' is not visible on the webpage content. It's ok if it's visible in the tab title.");

    expect(result).toBeTruthy();
  });
});
```

## How it works

* `find()` with `zoom: true` locates the element in two passes for extra precision. This helps with small targets like the address bar.
* `pressKeys(['ctrl', 'a'])` selects the current URL so `type()` replaces it.
* The test clicks the page before scrolling so the page, not the address bar, gets the scroll.
* `scroll('down', { amount: 1000 })` scrolls down with the mouse wheel.

## Run it

The test is in the [TestDriver SDK repository](https://github.com/testdriverai/testdriverai/tree/main/examples). Clone it, install dependencies, and run the file:

```bash theme={null}
git clone https://github.com/testdriverai/testdriverai
cd testdriverai
npm install
npx vitest run examples/navigate-and-scroll.test.mjs
```

The test reads your API key from `TD_API_KEY`. Create a key at [console.testdriver.ai/team/api-keys](https://console.testdriver.ai/team/api-keys). Then set it in your environment or a `.env` file.

## Related

* [scroll()](/scroll)
* [find()](/find)
* [focusApplication()](/focus-application)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.