> ## 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.

# Element Not Found Test

> Example test showing how to gracefully handle elements that don't exist on the page.

## Demo Test Run

Watch this test execute in a real sandbox environment:

<iframe src="https://api-test.testdriver.ai/api/v1/testdriver/testcase/6a051d492ca563f154801cd2/replay" width="100%" height="390" style={{ border: "1px solid #333", borderRadius: "8px" }} allow="fullscreen" />

## Source Code

```javascript title="element-not-found.test.mjs" {16-18} theme={null}
/**
 * TestDriver SDK - Element Not Found Test
 * Tests that finding a non-existent element returns properly without timing out
 */

import { describe, expect, it } from "vitest";
import { TestDriver } from "testdriverai/vitest/hooks";

describe("Element Not Found Test", () => {
  it("should handle non-existent element gracefully without timing out", async (context) => {
    const testdriver = TestDriver(context, { ip: context.ip || process.env.TD_IP, headless: true });
    await testdriver.provision.chrome({ url: 'http://testdriver-sandbox.vercel.app/login' });

    //

    // Try to find an element that definitely doesn't exist
    const element = await testdriver.find(
      "a purple unicorn dancing on the moon",
    );

    // Should return an element that is not found
    expect(element.found()).toBe(false);
    expect(element.coordinates).toBeNull();
  }); // 90 second timeout for the test (should complete much faster)
});
```

## Running This Example

```bash theme={null}
# Clone the TestDriver repository
git clone https://github.com/testdriverai/testdriverai

# Install dependencies
cd testdriverai
npm install

# Run this specific example
npx vitest run examples/element-not-found.test.mjs
```

<Note>
  Make sure you have `TD_API_KEY` set in your environment. Get one at [testdriver.ai](https://testdriver.ai).
</Note>
