> For the complete documentation index, see [llms.txt](https://help.autify.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.autify.com/nocode-web/en/when-the-test-doesnt-work/tips/how-to-fix-css-selector-errors.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# How to fix CSS selector errors

On this page, you will learn how to fix the "Element not found" error caused by an incorrect CSS selector. We assume that you already know how to:

* Read/write CSS and HTML
* Inspect HTML elements using Chrome DevTools

(To learn these first, please see the [related articles](#related-articles) section)

## Common causes and solutions

To start troubleshooting, let's check the current CSS selector.

Navigate to the failed step and click to see the CSS selector.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-a9fb470c55323089c644f76f498afc9d9f002de4%2Fcheck-css-selector.png?alt=media)

Let's take a look at the common causes and their solutions.

### 1. Auto-generated CSS selector

#### Cause

If your CSS selector looks very long, like the below example, it implies the CSS selector was auto-generated by DevTools.

```
#header-navigation > div > nav > div > div.d-none.d-lg-block.flex-grow-1.h-100 > div > div > div:nth-child(3) > a
```

While it may be quick and easy to get a CSS selector from DevTools, it tends to be fragile if the website's structure is updated frequently.

#### Solution

Find an id or a combination of classes that is unique to the element.

For example:

```
a#link_to_login_page
```

or

```
header a.navigation.login
```

If no ids or classes are available, you can specify other attributes using the attribute selector like this:

```
a[href="./login"]
```

or

```
a img[alt="login button"]
```

This way, you can get a selector that's immune to updates.

### 2. Random ids or classnames

If your CSS selector has a random string like the below example, it implies that the ids or classnames were generated by some build tool.

```
a.login_ac2187y3
```

The random part (prefix, suffix, or entire classname/id) might change after the build.

Again, you can solve this by using the attribute selector.

```
a[href="./login"]
```

Also, if it has a consistent part (`login`, in the above example), you can specify it using the wildcard syntax.

This matches the classname that contains the string "login":

```
a[class*="login"]
```

This matches the classname that start with "login":

```
a[class^="login"]
```

To learn more about attribute selectors, see [MDN Web Docs - Attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors).

## Tips

### How to confirm the "uniqueness" of your CSS selector

Follow the steps below to confirm that your selector matches only one element on the page:

1. Open the DevTools window.
2. Navigate to the Elements tab.
3. Press Ctrl + F (Windows) or Cmd + F (Mac) to open the search text box.
4. Input your CSS selector to the textbox.
5. Confirm the number of the elements found by the selector.

![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-fb9181f2867a82742d178df5dae99a00ee040530%2Funiqueness.png?alt=media)

## If you are still having trouble...

Contact our Customer Success team anytime. We will help you solve this issue. 🙂

## Related articles <a href="#related-articles" id="related-articles"></a>

* To learn CSS selector basics, see [Using CSS selectors effectively](https://help.autify.com/nocode-web/en/autify-university/advanced/locator-feature/how-to-use-css-selectors-effectively.md).
* To learn how to inspect an HTML element, see [Add a locator to specify an element](https://help.autify.com/nocode-web/en/autify-university/advanced/locator-feature/add-a-locator.md). Official documentation in [Chrome DevTools](https://developer.chrome.com/docs/devtools/overview/) may also be helpful.
* To learn about advanced syntaxes that you can use in CSS selectors, see [MDN Web Docs - Attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.autify.com/nocode-web/en/when-the-test-doesnt-work/tips/how-to-fix-css-selector-errors.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
