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

# wait-for-image

> Wait until an image matching the description is detected on the screen.

<div className="replay-block">
  <iframe src="https://app.dashcam.io/replay/68a598d23f4291f46c418d46?share=i2XOttSHoFjIVWd6uSjGQ&embed=true&timestamp=90000&playbackRate=5" width="1000" height="350" />
</div>

```yaml highlight={14-17} theme={null}
version: 6.0.0
steps:
  - prompt: go to testdriver.ai and wait for the hero image to load
    commands:
      - command: press-keys
        keys:
          - ctrl
          - l
      - command: type
        text: testdriver.ai
      - command: press-keys
        keys:
          - enter
      - command: wait-for-image
        description: the hero section image
        timeout: 10000 # 10 seconds
```

## Description

The `wait-for-image` command waits until the specified image is detected on the screen. This is useful for ensuring that visual elements are present before proceeding with the next steps in a test.

## Arguments

|    Argument   |    Type   | Description                                                                                                       |
| :-----------: | :-------: | :---------------------------------------------------------------------------------------------------------------- |
| `description` |  `string` | A description of the image.                                                                                       |
|   `timeout`   |  `number` | (Optional) The duration in milliseconds to wait for the image to appear. Default is `10000` (10 seconds).         |
|    `invert`   | `boolean` | (Optional) If set to `true`, the command will wait until the specified image is NOT detected. Default is `false`. |

## Example usage

```yaml theme={null}
command: wait-for-image
description: trash icon
timeout: 5000
```

## Protips

* Use clear and concise descriptions for the image to improve detection accuracy.
* Adjust the `timeout` value based on the expected load time of the image to avoid unnecessary delays.

<Tip>
  If you are unable to land on an accurate description or experiencing flaky
  results, try to upload the image to [chatgpt](https://chatgpt.com) and ask it
  to describe the image and use the generated `description` to get better
  accuracy and determinism.
</Tip>

## Gotchas

* If the image doesn't appear within the specified `timeout`, the command will fail.
* Ensure the description accurately represents the image to avoid detection issues.

***

The `wait-for-image` command is ideal for synchronizing tests with visual elements that may take time to load.
