> 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/autify-university/advanced/locator-feature/how-to-get-css-selectors.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# How to get CSS selectors / XPath

If you are unsure how to specify the CSS selector / XPath when adding a locator to a scenario in Autify, you can check the CSS selector / XPath of the target element in the Google Chrome Developer Tools (henceforth Developer Tools).

This page explains how to get the CSS selector / XPath of an element using DevTools. Please check the related articles for more information on how to specify elements more stably and for errors that occur after acquisition.

{% hint style="info" %}
[DevTools](https://developer.chrome.com/docs/devtools/) is a set of web developer tools built directly into the Google Chrome browser. (Source: official website)

\**There are some differences in the UI between the Windows and Mac versions. In this article, we have used the Mac version.*
{% endhint %}

## How to launch Developer Tools

There are three ways to launch Chrome DevTools.

1. Click the \[︙] icon in the upper right corner of Chrome
   1. Click the \[︙] icon in the upper right corner of Chrome.
   2. From the menu, click \[More Tools] > \[Developer Tools].

      ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-e3095ae41bcffea49cbb12e13781503cea7c614f%2FEn_Chrome%20%E3%81%AE%E5%8F%B3%E4%B8%8A%E3%81%AB%E3%81%82%E3%82%8B%E3%80%8C%EF%B8%99%E3%80%8D%E3%83%A1%E3%83%8B%E3%83%A5%E3%83%BC%E3%81%8B%E3%82%89%E8%B5%B7%E5%8B%95.png?alt=media)
2. Open the right-click menu with your mouse
   1. Right mouse click on the target element to display the menu.
   2. You can launch DevTools by clicking \[Inspect].

      ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-d8ab78c433aa22d5dd0e1b2f01b9d03effcd9108%2Fimage\(45\).png?alt=media)
3. Use a shortcut key You can launch Chrome DevTools using the following shortcut keys:

   ```
   Windows: Ctrl + Shift + I
   Mac: Cmd + Opt + I
   ```

{% hint style="info" %}
You can change where DevTools is displayed by clicking the \[︙] icon at the upper right corner of Developer Tools and selecting "Dock side".

<img src="https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-51a059e9607894f90ec0409dbda215c36c6bf00f%2FEn_%E8%A1%A8%E7%A4%BA%E4%BD%8D%E7%BD%AE%E3%81%AE%E5%A4%89%E6%9B%B4%E6%96%B9%E6%B3%95(1).png?alt=media" alt="" data-size="original">
{% endhint %}

## How to get a CSS selector / XPath for a target element

We will use the heading on the [Autify's home page](https://autify.com/) "Faster Release Cycle AI-Powered Software Test Automation" as an example.

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

1. Switch to Selection Mode on Developer Tools
   1. Make sure the Elements tab is open in DevTools.
   2. Switch to Selection Mode by clicking the icon in the upper left corner of DevTools.
2. Select the target element
   1. With the DevTool in Selection Mode, select the target element on the page with your mouse.
   2. The source code corresponding to the element is selected.

      ![](https://1964297753-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVdZPTgwISYb3LhjgKnw6%2Fuploads%2Fgit-blob-fd321a839efabf4908adce8db0d8842281181942%2FEn_%E5%AF%BE%E8%B1%A1%E8%A6%81%E7%B4%A0%E3%82%92%E9%81%B8%E6%8A%9E%E3%81%99%E3%82%8B_%E9%81%B8%E6%8A%9E%E4%B8%AD\(1\).png?alt=media)
3. Get the CSS selector / XPath of the target element
   1. Move the mouse cursor to the selected source code in DevTools and right-click it.
   2. Each of the below operations will copy the value of the target element to the clipboard. CSS selector: Click \[Copy] > \[Copy selector] from the menu. XPath: Click \[Copy] > \[Copy selector] from the menu.
   3. Paste the value copied into a text editor.

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

In this example, we got the following values.

* CSS selector

```
body > main > div:nth-child(3) > div > div > div > div.web-steps-heading.text-center > h3
```

* XPath

```
/html/body/main/div[3]/div/div/div/div[1]/h3
```

<br>

{% hint style="info" %}
With CSS selectors / XPath, there can be more than one way to select an element. In automated testing, it’s important to choose a method that:

* reflects your intentions,
* can identify the target without ambiguity,
* is concise and does not break easily (is resistant to changes in page structure)

For information on how to change the method of specifying the CSS selector you have got, please refer to this article.: [Using CSS selectors effectively](https://help.autify.com/nocode-web/en/autify-university/advanced/locator-feature/how-to-use-css-selectors-effectively.md)
{% endhint %}

<br>

## How to validate CSS selector / XPath <a href="#how-to-validate-css-selector-xpath" id="how-to-validate-css-selector-xpath"></a>

If you want to validate if the CSS selector / XPath you got is the intended element when you change the way to specify it, you can use the following command in the "Elements" panel of the Developer Tools to call the search window and search for the element.

```
Windows：Ctrl　+　F
macOS：command　+　F
```

Let's take the CSS selector as an example.(XPath can be verified in the same way.) Change the CSS selector as follows and verify that the intended element is specified.

```
Before change：body > main > div:nth-child(3) > div > div > div > div.web-steps-heading.text-center > h3
After change：.web-steps-heading.text-center > h3
```

Enter the CSS selector in the search window in the lower right corner, and if the element can be specified, the corresponding element will be highlighted.

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

{% hint style="info" %}

* If nothing is searched, check the statement in the CSS selector.
* If multiple elements are searched, the locator may identify an unintended element. If this is the case, fix the statement so that the unique target element can be specified.
  {% endhint %}

## Related articles

* [Add a locator to specify an element](https://help.autify.com/nocode-web/en/autify-university/advanced/locator-feature/add-a-locator.md)
* [Using CSS selectors effectively](https://help.autify.com/nocode-web/en/autify-university/advanced/locator-feature/how-to-use-css-selectors-effectively.md)
* [Element Not Found](https://help.autify.com/nocode-web/en/when-the-test-doesnt-work/common-errors/element-not-found.md)


---

# 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/autify-university/advanced/locator-feature/how-to-get-css-selectors.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.
