> 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/tips-1/select-box-tips/select-the-nth-of-options.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# Select the Nth option from a list

## Selecting the Nth Option from a List

In a [Select a value from a list](https://help.autify.com/nocode-web/en/autify-university/foundation/creating-a-scenario/select-from-list-by-label.md) step, the option is selected based on its label, so you cannot use it to select the Nth option.

However, you can achieve the same action by combining "[JS Steps for Elements](https://help.autify.com/nocode-web/en/autify-university/advanced/js-steps/js-steps-for-elements.md)" and the "Select a value from a list" step.

{% hint style="warning" %}
**Note**

The method described here cannot be used for lists that aren't implemented using the `<select>` element.
{% endhint %}

### Benefits of Using JS Steps for Elements

Using a regular JS step, it's possible to select the Nth option from a list with a single JS step. However, on this page, we will show you how to combine "JS Steps for Elements" with the "Select a value from a list" step, as using "JS Steps for Elements" has the following advantages:

* Autify AI gets the element, so you don't have to get its CSS selector/XPath.
* Requires less code, since you don't need to write code to get the element.
* Automatically waits for the page to finish loading and for the element to appear.

## Record and Edit the Scenario

First, right-click on the target list and select ***\[Autify Recorder]*** > ***\[Add JS Step]***. Next, select the appropriate value from the list and click ***\[Save]***.

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

This will create two steps: "Execute JavaScript" (we'll call this step as "JS Step for Element") and "Select ... from List".

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

Open the *JS Step for Element* and paste the following code. Autify will get the element, so less code is needed.

```javascript
// The index of the list starts at 0, so if you want to select the fourth option, specify 3.
const index = 3;

// -- No need to change from here on down --
// Obtains the label with the specified index number.
const label = element.options[index].label;

// The obtained label is returned and made available for use in subsequent steps.
return label;
```

The section below specifies the index number of the option. Since the index starts at 0, set it to 3 if you want to select the 4th option.

```javascript
const index = 3;
```

Next, click the **Select ... from List** step, change the label value to "Other step's result", specify the *JS Step for Element*, and save. Now it will select the label obtained in the *JS Step for Element*.

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

## Run the Test

Let's run the test.

Looking at the result, we can confirm that the return value of the *JS Step for Element* is the expected label value.

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

The list value is also changed to the returned value.

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


---

# 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/tips-1/select-box-tips/select-the-nth-of-options.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.
