<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>FrameLocator on Grafana Labs</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/</link><description>Recent content in FrameLocator on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/index.xml" rel="self" type="application/rss+xml"/><item><title>frameLocator(selector)</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/framelocator/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/framelocator/</guid><content><![CDATA[&lt;h1 id=&#34;framelocatorselector&#34;&gt;frameLocator(selector)&lt;/h1&gt;
&lt;p&gt;Returns a 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/&#34;&gt;FrameLocator&lt;/a&gt; for a nested iframe that matches the given &lt;code&gt;selector&lt;/code&gt; within this frame. Use this to chain frame locators for nested iframes.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;selector&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;A selector that resolves to an iframe element (for example &lt;code&gt;iframe#inner&lt;/code&gt; or &lt;code&gt;iframe[name=&amp;quot;nested&amp;quot;]&lt;/code&gt;).&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/&#34;&gt;FrameLocator&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A &lt;code&gt;FrameLocator&lt;/code&gt; for the matched nested iframe.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    browser: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    await page.setContent(`
      &amp;lt;iframe id=&amp;#34;outer&amp;#34; srcdoc=&amp;#34;&amp;lt;iframe id=&amp;#39;inner&amp;#39; srcdoc=&amp;#39;&amp;lt;button&amp;gt;Submit&amp;lt;/button&amp;gt;&amp;#39;&amp;gt;&amp;lt;/iframe&amp;gt;&amp;#34;&amp;gt;&amp;lt;/iframe&amp;gt;
    `);

    // Nested iframes: outer frame, then inner frame, then element
    const button = page.frameLocator(&amp;#39;#outer&amp;#39;).frameLocator(&amp;#39;#inner&amp;#39;).locator(&amp;#39;button&amp;#39;);
    await button.click();
  } finally {
    await page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="framelocatorselector">frameLocator(selector)&lt;/h1>
&lt;p>Returns a
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/">FrameLocator&lt;/a> for a nested iframe that matches the given &lt;code>selector&lt;/code> within this frame. Use this to chain frame locators for nested iframes.&lt;/p>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Parameter&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>selector&lt;/td>
&lt;td>string&lt;/td>
&lt;td>A selector that resolves to an iframe element (for example &lt;code>iframe#inner&lt;/code> or &lt;code>iframe[name=&amp;quot;nested&amp;quot;]&lt;/code>).&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="returns">Returns&lt;/h3>
&lt;section class="expand-table-wrapper">&lt;div class="button-div">
&lt;button class="expand-table-btn">Expand table&lt;/button>
&lt;/div>&lt;div class="responsive-table-wrapper">
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/">FrameLocator&lt;/a>&lt;/td>
&lt;td>A &lt;code>FrameLocator&lt;/code> for the matched nested iframe.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;/div>
&lt;/section>&lt;h3 id="example">Example&lt;/h3>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">JavaScript&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-javascript">import { browser } from &amp;#39;k6/browser&amp;#39;;
export const options = {
scenarios: {
browser: {
executor: &amp;#39;shared-iterations&amp;#39;,
options: {
browser: {
type: &amp;#39;chromium&amp;#39;,
},
},
},
},
};
export default async function () {
const page = await browser.newPage();
try {
await page.setContent(`
&amp;lt;iframe id=&amp;#34;outer&amp;#34; srcdoc=&amp;#34;&amp;lt;iframe id=&amp;#39;inner&amp;#39; srcdoc=&amp;#39;&amp;lt;button&amp;gt;Submit&amp;lt;/button&amp;gt;&amp;#39;&amp;gt;&amp;lt;/iframe&amp;gt;&amp;#34;&amp;gt;&amp;lt;/iframe&amp;gt;
`);
// Nested iframes: outer frame, then inner frame, then element
const button = page.frameLocator(&amp;#39;#outer&amp;#39;).frameLocator(&amp;#39;#inner&amp;#39;).locator(&amp;#39;button&amp;#39;);
await button.click();
} finally {
await page.close();
}
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div></description></item><item><title>getByAltText(altText[, options])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyalttext/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyalttext/</guid><content><![CDATA[

&lt;div data-shared=&#34;browser/getby-apis/getbyalttext-spec.md&#34;&gt;
            &lt;h1 id=&#34;getbyalttextalttext-options&#34;&gt;getByAltText(altText[, options])&lt;/h1&gt;
&lt;p&gt;Returns a locator for elements with the specified alt text. This method is useful for locating images and other elements that have an &lt;code&gt;alt&lt;/code&gt; attribute, making your tests more accessible and user-focused.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;altText&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string | RegExp&lt;/td&gt;
              &lt;td&gt;-&lt;/td&gt;
              &lt;td&gt;Required. The alt text to search for. Can be a string for exact match or a RegExp for pattern matching.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;object&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.exact&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Whether to match the alt text exactly with case sensitivity. When &lt;code&gt;true&lt;/code&gt;, performs a case-sensitive match.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/locator/&#34;&gt;Locator&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A locator object that can be used to interact with elements matching the specified alt text.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;basic-alt-text-matching&#34;&gt;Basic alt text matching&lt;/h3&gt;
&lt;p&gt;Find and click an image by its alt text:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    ui: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    await page.setContent(`
      &amp;lt;iframe id=&amp;#34;my_frame&amp;#34; src=&amp;#34;https://quickpizza.grafana.com&amp;#34; width=&amp;#34;50%&amp;#34; height=&amp;#34;50%&amp;#34;&amp;gt;&amp;lt;/iframe&amp;gt;
    `);

    const logo = page.locator(&amp;#39;#my_frame&amp;#39;).contentFrame().getByAltText(&amp;#39;LOGO&amp;#39;);
    await logo.waitFor();

    await logo.click();
    await page.waitForLoadState();
  } finally {
    await page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exact-alt-text-matching&#34;&gt;Exact alt text matching&lt;/h3&gt;
&lt;p&gt;Use exact matching for precise alt text:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    ui: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    await page.setContent(`
      &amp;lt;iframe id=&amp;#34;my_frame&amp;#34; src=&amp;#34;https://quickpizza.grafana.com&amp;#34; width=&amp;#34;50%&amp;#34; height=&amp;#34;50%&amp;#34;&amp;gt;&amp;lt;/iframe&amp;gt;
    `);

    const logo = page.locator(&amp;#39;#my_frame&amp;#39;).contentFrame().getByAltText(&amp;#39;logo&amp;#39;, { exact: true });
    await logo.waitFor();

    await logo.click();
    await page.waitForLoadState();
  } finally {
    await page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;using-regular-expressions&#34;&gt;Using regular expressions&lt;/h3&gt;
&lt;p&gt;Find images using pattern matching:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    ui: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    await page.setContent(`
      &amp;lt;iframe id=&amp;#34;my_frame&amp;#34; src=&amp;#34;https://quickpizza.grafana.com&amp;#34; width=&amp;#34;50%&amp;#34; height=&amp;#34;50%&amp;#34;&amp;gt;&amp;lt;/iframe&amp;gt;
    `);

    const logo = page.locator(&amp;#39;#my_frame&amp;#39;).contentFrame().getByAltText(/logo/s);
    await logo.waitFor();

    await logo.click();
    await page.waitForLoadState();
  } finally {
    await page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div data-shared=&#34;browser/getby-apis/getbyalttext-tips.md&#34;&gt;
            &lt;h2 id=&#34;common-use-cases&#34;&gt;Common use cases&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Image testing:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Testing image alt text for accessibility compliance&lt;/li&gt;
&lt;li&gt;Interacting with clickable images/banners&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Accessibility testing:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Ensuring all images have meaningful alt text&lt;/li&gt;
&lt;li&gt;Testing screen reader compatibility&lt;/li&gt;
&lt;li&gt;Validating WCAG compliance&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;UI interaction:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Clicking on logo images to navigate home&lt;/li&gt;
&lt;li&gt;Selecting images in galleries or carousels&lt;/li&gt;
&lt;li&gt;Interacting with image-based buttons&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Use descriptive alt text&lt;/strong&gt;: When creating tests, ensure your application uses meaningful alt text that describes the image content or function.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prefer exact matches&lt;/strong&gt;: Use &lt;code&gt;exact: true&lt;/code&gt; when you need precise matching to avoid false positives.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Accessibility-first&lt;/strong&gt;: Using &lt;code&gt;getByAltText()&lt;/code&gt; encourages better accessibility practices by ensuring images have proper alt attributes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Regular expressions for patterns&lt;/strong&gt;: Use RegExp for flexible matching when dealing with dynamic or numbered content.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Combine with assertions&lt;/strong&gt;: Always verify that the located elements behave as expected using assertions.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

        
&lt;h2 id=&#34;related&#34;&gt;Related&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyrole/&#34;&gt;frameLocator.getByRole()&lt;/a&gt; - Locate by ARIA role&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbylabel/&#34;&gt;frameLocator.getByLabel()&lt;/a&gt; - Locate by form labels&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyplaceholder/&#34;&gt;frameLocator.getByPlaceholder()&lt;/a&gt; - Locate by placeholder text&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytestid/&#34;&gt;frameLocator.getByTestId()&lt;/a&gt; - Locate by test ID&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytitle/&#34;&gt;frameLocator.getByTitle()&lt;/a&gt; - Locate by title attribute&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytext/&#34;&gt;frameLocator.getByText()&lt;/a&gt; - Locate by visible text&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;div data-shared="browser/getby-apis/getbyalttext-spec.md">
&lt;h1 id="getbyalttextalttext-options">getByAltText(altText[, options])&lt;/h1>
&lt;p>Returns a locator for elements with the specified alt text. This method is useful for locating images and other elements that have an &lt;code>alt&lt;/code> attribute, making your tests more accessible and user-focused.&lt;/p></description></item><item><title>getByLabel(text[, options])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbylabel/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbylabel/</guid><content><![CDATA[

&lt;div data-shared=&#34;browser/getby-apis/getbylabel-spec.md&#34;&gt;
            &lt;h1 id=&#34;getbylabeltext-options&#34;&gt;getByLabel(text[, options])&lt;/h1&gt;
&lt;p&gt;Returns a locator for form controls associated with the specified label text. This method is ideal for interacting with form elements in an accessible and user-focused way, as it mirrors how users typically identify form fields.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;text&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string | RegExp&lt;/td&gt;
              &lt;td&gt;-&lt;/td&gt;
              &lt;td&gt;Required. The label text to search for. Can be a string for exact match or a RegExp for pattern matching.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;object&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.exact&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Whether to match the label text exactly with case sensitivity. When &lt;code&gt;true&lt;/code&gt;, performs a case-sensitive match.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/locator/&#34;&gt;Locator&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A locator object that can be used to interact with the form control associated with the specified label.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;basic-form-interaction&#34;&gt;Basic form interaction&lt;/h3&gt;
&lt;p&gt;Fill form fields using their labels:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    ui: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    const iframeHTML = `
      &amp;lt;label for=&amp;#34;username&amp;#34;&amp;gt;Username (hint: default)&amp;lt;/label&amp;gt;
      &amp;lt;input type=&amp;#34;text&amp;#34; id=&amp;#34;username&amp;#34; name=&amp;#34;username&amp;#34;&amp;gt;
      &amp;lt;label for=&amp;#34;password&amp;#34;&amp;gt;Password (hint: 12345678)&amp;lt;/label&amp;gt;
      &amp;lt;input type=&amp;#34;password&amp;#34; id=&amp;#34;password&amp;#34; name=&amp;#34;password&amp;#34;&amp;gt;
    `;

    await page.setContent(`
      &amp;lt;iframe id=&amp;#34;my_frame&amp;#34; src=&amp;#34;data:text/html,${encodeURIComponent(iframeHTML)}&amp;#34;&amp;gt;&amp;lt;/iframe&amp;gt;
    `);

    const frameLocator = page.locator(&amp;#34;#my_frame&amp;#34;).contentFrame();
    const username = frameLocator.getByLabel(&amp;#39;Username (hint: default)&amp;#39;, { exact: true });
    const password = frameLocator.getByLabel(/^Password.*$/);

    await username.fill(&amp;#39;default&amp;#39;);
    await password.fill(&amp;#39;12345678&amp;#39;);
  } finally {
    await page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;working-with-different-input-types&#34;&gt;Working with different input types&lt;/h3&gt;
&lt;p&gt;Handle various form control types in various label association patterns:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    browser: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    const iframeHTML = `
      &amp;lt;label for=&amp;#34;username&amp;#34;&amp;gt;Username (hint: default)&amp;lt;/label&amp;gt;
      &amp;lt;input type=&amp;#34;text&amp;#34; id=&amp;#34;username&amp;#34; name=&amp;#34;username&amp;#34;&amp;gt;
      &amp;lt;span id=&amp;#34;password-label&amp;#34;&amp;gt;Password (hint: 12345678)&amp;lt;/span&amp;gt;
      &amp;lt;input type=&amp;#34;password&amp;#34; aria-labelledby=&amp;#34;password-label&amp;#34;&amp;gt;
      &amp;lt;label for=&amp;#34;subscribe&amp;#34;&amp;gt;Subscribe to newsletter&amp;lt;/label&amp;gt;
      &amp;lt;input type=&amp;#34;checkbox&amp;#34; id=&amp;#34;subscribe&amp;#34; name=&amp;#34;subscribe&amp;#34;&amp;gt;
      &amp;lt;label for=&amp;#34;email&amp;#34;&amp;gt;Email&amp;lt;/label&amp;gt;
      &amp;lt;input type=&amp;#34;radio&amp;#34; id=&amp;#34;email&amp;#34; value=&amp;#34;email&amp;#34;&amp;gt;
      &amp;lt;label for=&amp;#34;sms&amp;#34;&amp;gt;Text message&amp;lt;/label&amp;gt;
      &amp;lt;input type=&amp;#34;radio&amp;#34; id=&amp;#34;sms&amp;#34; value=&amp;#34;sms&amp;#34;&amp;gt;
      &amp;lt;label for=&amp;#34;theme&amp;#34;&amp;gt;Theme&amp;lt;/label&amp;gt;
      &amp;lt;select id=&amp;#34;theme&amp;#34; name=&amp;#34;theme&amp;#34;&amp;gt;
        &amp;lt;option value=&amp;#34;light&amp;#34;&amp;gt;Light&amp;lt;/option&amp;gt;
        &amp;lt;option value=&amp;#34;dark&amp;#34;&amp;gt;Dark&amp;lt;/option&amp;gt;
        &amp;lt;option value=&amp;#34;system&amp;#34;&amp;gt;System&amp;lt;/option&amp;gt;
      &amp;lt;/select&amp;gt;
      &amp;lt;textarea aria-label=&amp;#34;Comments&amp;#34;&amp;gt;&amp;lt;/textarea&amp;gt;
    `;

    await page.setContent(`
      &amp;lt;iframe id=&amp;#34;my_frame&amp;#34; src=&amp;#34;data:text/html,${encodeURIComponent(iframeHTML)}&amp;#34;&amp;gt;&amp;lt;/iframe&amp;gt;
    `);

    const frameLocator = page.locator(&amp;#34;#my_frame&amp;#34;).contentFrame();

    // Inputs
    await frameLocator.getByLabel(&amp;#39;Username (hint: default)&amp;#39;, { exact: true }).fill(&amp;#39;default&amp;#39;);
    await frameLocator.getByLabel(/^Password.*$/).fill(&amp;#39;12345678&amp;#39;);

    // Checkbox
    await frameLocator.getByLabel(&amp;#39;Subscribe to newsletter&amp;#39;).check();

    // Radio button
    await frameLocator.getByLabel(&amp;#39;Email&amp;#39;, { exact: true }).check();

    // Select dropdown
    await frameLocator.getByLabel(&amp;#39;Theme&amp;#39;).selectOption(&amp;#39;light&amp;#39;);

    // Textarea
    await frameLocator.getByLabel(&amp;#39;Comments&amp;#39;).fill(&amp;#39;This is a test comment&amp;#39;);
  } finally {
    await page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div data-shared=&#34;browser/getby-apis/getbylabel-tips.md&#34;&gt;
            &lt;h2 id=&#34;label-association-patterns&#34;&gt;Label association patterns&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;getByLabel()&lt;/code&gt; method works with several HTML patterns for associating labels with form controls:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Explicit association with &lt;code&gt;for&lt;/code&gt; attribute:&lt;/p&gt;
&lt;!-- eslint-skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;HTML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-html&#34;&gt;&amp;lt;label for=&amp;#34;username&amp;#34;&amp;gt;Username&amp;lt;/label&amp;gt; &amp;lt;input type=&amp;#34;text&amp;#34; id=&amp;#34;username&amp;#34; name=&amp;#34;username&amp;#34; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;ARIA labeling:&lt;/p&gt;
&lt;!-- eslint-skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;HTML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-html&#34;&gt;&amp;lt;span id=&amp;#34;username-label&amp;#34;&amp;gt;Username&amp;lt;/span&amp;gt; &amp;lt;input type=&amp;#34;text&amp;#34; aria-labelledby=&amp;#34;username-label&amp;#34; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;ARIA label attribute:&lt;/p&gt;
&lt;!-- eslint-skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;HTML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-html&#34;&gt;&amp;lt;input type=&amp;#34;text&amp;#34; aria-label=&amp;#34;Username&amp;#34; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;common-use-cases&#34;&gt;Common use cases&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Form testing&lt;/strong&gt;: Login forms, registration forms, contact forms&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;E-commerce&lt;/strong&gt;: Checkout forms, shipping information, payment details&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Settings pages&lt;/strong&gt;: User preferences, account settings, configuration forms&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Accessibility testing&lt;/strong&gt;: Ensuring proper label association and screen reader compatibility&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Accessibility-first approach&lt;/strong&gt;: Using &lt;code&gt;getByLabel()&lt;/code&gt; ensures your tests work the same way users with assistive technology interact with forms.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Meaningful labels&lt;/strong&gt;: Encourage developers to use descriptive, unique label text that clearly identifies the form control&amp;rsquo;s purpose.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Required field indicators&lt;/strong&gt;: When testing required fields, include any visual indicators (like asterisks) in your label text matching.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Form validation testing&lt;/strong&gt;: Use labels to test form validation scenarios, as they provide a stable way to identify fields regardless of styling changes.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

        
&lt;h2 id=&#34;related&#34;&gt;Related&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyrole/&#34;&gt;frameLocator.getByRole()&lt;/a&gt; - Locate by ARIA role&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyalttext/&#34;&gt;frameLocator.getByAltText()&lt;/a&gt; - Locate by alt text&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyplaceholder/&#34;&gt;frameLocator.getByPlaceholder()&lt;/a&gt; - Locate by placeholder text&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytestid/&#34;&gt;frameLocator.getByTestId()&lt;/a&gt; - Locate by test ID&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytitle/&#34;&gt;frameLocator.getByTitle()&lt;/a&gt; - Locate by title attribute&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytext/&#34;&gt;frameLocator.getByText()&lt;/a&gt; - Locate by text content&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;div data-shared="browser/getby-apis/getbylabel-spec.md">
&lt;h1 id="getbylabeltext-options">getByLabel(text[, options])&lt;/h1>
&lt;p>Returns a locator for form controls associated with the specified label text. This method is ideal for interacting with form elements in an accessible and user-focused way, as it mirrors how users typically identify form fields.&lt;/p></description></item><item><title>getByPlaceholder(placeholder[, options])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyplaceholder/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyplaceholder/</guid><content><![CDATA[

&lt;div data-shared=&#34;browser/getby-apis/getbyplaceholder-spec.md&#34;&gt;
            &lt;h1 id=&#34;getbyplaceholderplaceholder-options&#34;&gt;getByPlaceholder(placeholder[, options])&lt;/h1&gt;
&lt;p&gt;Returns a locator for input elements with the specified &lt;code&gt;placeholder&lt;/code&gt; attribute. This method is useful for locating form fields that use &lt;code&gt;placeholder&lt;/code&gt; attribute to provide hints or examples to users about the expected input format.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;placeholder&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string | RegExp&lt;/td&gt;
              &lt;td&gt;-&lt;/td&gt;
              &lt;td&gt;Required. The placeholder text to search for. Can be a string for exact match or a RegExp for pattern matching.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;object&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.exact&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Whether to match the placeholder text exactly with case sensitivity. When &lt;code&gt;true&lt;/code&gt;, performs a case-sensitive match.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/locator/&#34;&gt;Locator&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A locator object that can be used to interact with the input elements matching the specified placeholder text.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;Find and fill inputs by their placeholder text:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    browser: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    const iframeHTML = `
      &amp;lt;input type=&amp;#34;text&amp;#34; placeholder=&amp;#34;First name&amp;#34;&amp;gt;
      &amp;lt;input type=&amp;#34;text&amp;#34; placeholder=&amp;#34;Last name&amp;#34;&amp;gt;
      &amp;lt;input type=&amp;#34;text&amp;#34; placeholder=&amp;#34;dd/mm/yyyy&amp;#34;&amp;gt;
      &amp;lt;input type=&amp;#34;text&amp;#34; placeholder=&amp;#34;your.email@example.com&amp;#34;&amp;gt;
      &amp;lt;input type=&amp;#34;text&amp;#34; placeholder=&amp;#34;&amp;#43;1 (555) 123-4567&amp;#34;&amp;gt;
    `;

    await page.setContent(`
      &amp;lt;iframe id=&amp;#34;my_frame&amp;#34; src=&amp;#34;data:text/html,${encodeURIComponent(iframeHTML)}&amp;#34;&amp;gt;&amp;lt;/iframe&amp;gt;
    `);

    const frameLocator = page.locator(&amp;#34;#my_frame&amp;#34;).contentFrame();
    await frameLocator.getByPlaceholder(&amp;#39;First name&amp;#39;).fill(&amp;#39;First&amp;#39;);
    await frameLocator.getByPlaceholder(&amp;#39;Last name&amp;#39;).fill(&amp;#39;Last&amp;#39;);
    await frameLocator.getByPlaceholder(&amp;#39;dd/mm/yyyy&amp;#39;).fill(&amp;#39;01/01/1990&amp;#39;);

    await frameLocator.getByPlaceholder(&amp;#39;your.email@example.com&amp;#39;).fill(&amp;#39;first.last@example.com&amp;#39;);
    await frameLocator.getByPlaceholder(&amp;#39;&amp;#43;1 (555) 123-4567&amp;#39;).fill(&amp;#39;&amp;#43;1 (555) 987-6543&amp;#39;);
  } finally {
    await page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div data-shared=&#34;browser/getby-apis/getbyplaceholder-tips.md&#34;&gt;
            &lt;h2 id=&#34;common-use-cases&#34;&gt;Common use cases&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Form field identification:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Login and registration forms without explicit labels&lt;/li&gt;
&lt;li&gt;Quick search boxes&lt;/li&gt;
&lt;li&gt;Filter and input controls&lt;/li&gt;
&lt;li&gt;Comment and feedback forms&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;E-commerce:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Product search bars&lt;/li&gt;
&lt;li&gt;Quantity input fields&lt;/li&gt;
&lt;li&gt;Promo code entry&lt;/li&gt;
&lt;li&gt;Address and payment information&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interactive applications:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Chat input fields&lt;/li&gt;
&lt;li&gt;Command input interfaces&lt;/li&gt;
&lt;li&gt;Settings and configuration forms&lt;/li&gt;
&lt;li&gt;Data entry applications&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Complement, don&amp;rsquo;t replace labels&lt;/strong&gt;: Placeholder text should supplement, not replace proper form labels for accessibility.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use descriptive placeholders&lt;/strong&gt;: Ensure placeholder text clearly indicates the expected input format or content.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consider internationalization&lt;/strong&gt;: When testing multi-language applications, be aware that placeholder text may change.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Accessibility considerations&lt;/strong&gt;: Remember that placeholder text alone may not be sufficient for users with disabilities.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

        
&lt;h2 id=&#34;related&#34;&gt;Related&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyrole/&#34;&gt;frameLocator.getByRole()&lt;/a&gt; - Locate by ARIA role&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyalttext/&#34;&gt;frameLocator.getByAltText()&lt;/a&gt; - Locate by alt text&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbylabel/&#34;&gt;frameLocator.getByLabel()&lt;/a&gt; - Locate by form labels (preferred for accessibility)&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytestid/&#34;&gt;frameLocator.getByTestId()&lt;/a&gt; - Locate by test ID&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytitle/&#34;&gt;frameLocator.getByTitle()&lt;/a&gt; - Locate by title attribute&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytext/&#34;&gt;frameLocator.getByText()&lt;/a&gt; - Locate by visible text&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;div data-shared="browser/getby-apis/getbyplaceholder-spec.md">
&lt;h1 id="getbyplaceholderplaceholder-options">getByPlaceholder(placeholder[, options])&lt;/h1>
&lt;p>Returns a locator for input elements with the specified &lt;code>placeholder&lt;/code> attribute. This method is useful for locating form fields that use &lt;code>placeholder&lt;/code> attribute to provide hints or examples to users about the expected input format.&lt;/p></description></item><item><title>getByRole(role[, options])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyrole/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyrole/</guid><content><![CDATA[

&lt;div data-shared=&#34;browser/getby-apis/getbyrole-spec.md&#34;&gt;
            &lt;h1 id=&#34;getbyrolerole-options&#34;&gt;getByRole(role[, options])&lt;/h1&gt;
&lt;p&gt;Returns a locator for elements with the specified ARIA role. This is the preferred way to locate elements as it most closely resembles how users and assistive technology perceive the page.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;role&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;-&lt;/td&gt;
              &lt;td&gt;Required. The ARIA role to search for. For example, &lt;code&gt;&#39;button&#39;&lt;/code&gt;, &lt;code&gt;&#39;link&#39;&lt;/code&gt;, &lt;code&gt;&#39;heading&#39;&lt;/code&gt;, or &lt;code&gt;&#39;textbox&#39;&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;options&lt;/td&gt;
              &lt;td&gt;object&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.checked&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filter elements by their checked state. Only applicable for roles like &lt;code&gt;checkbox&lt;/code&gt;, &lt;code&gt;radio&lt;/code&gt;, &lt;code&gt;menuitemcheckbox&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.disabled&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filter elements by their disabled state.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.exact&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Whether to match the accessible name exactly with case sensitivity. When &lt;code&gt;true&lt;/code&gt;, performs a case-sensitive match.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.expanded&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filter elements by their expanded state. Only applicable for roles that support the &lt;code&gt;aria-expanded&lt;/code&gt; attribute.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.includeHidden&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Whether to include elements that are normally excluded from the accessibility tree in the search.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.level&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;number&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filter headings by their level 1 to 6. Only applicable for &lt;code&gt;heading&lt;/code&gt; role.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.name&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string|RegExp&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filter elements by their accessible name. The accessible name is typically the text content, label text, or aria-label attribute.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.pressed&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filter elements by their pressed state. Only applicable for roles like &lt;code&gt;button&lt;/code&gt; with toggle behavior.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.selected&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filter elements by their selected state. Only applicable for roles like &lt;code&gt;option&lt;/code&gt;, &lt;code&gt;tab&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/locator/&#34;&gt;Locator&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A locator object that can be used to interact with the elements matching the specified role and options.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;basic-role-selection&#34;&gt;Basic role selection&lt;/h3&gt;
&lt;p&gt;Find and click a button by its role:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    browser: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    await page.setContent(`
      &amp;lt;iframe id=&amp;#34;my_frame&amp;#34; src=&amp;#34;https://quickpizza.grafana.com&amp;#34; width=&amp;#34;50%&amp;#34; height=&amp;#34;50%&amp;#34;&amp;gt;&amp;lt;/iframe&amp;gt;
    `);

    const frameLocator = page.locator(&amp;#39;#my_frame&amp;#39;).contentFrame();
    await frameLocator.getByRole(&amp;#39;button&amp;#39;, { name: &amp;#39;Pizza, Please!&amp;#39; }).click();
  } finally {
    page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div data-shared=&#34;browser/getby-apis/getbyrole-tips.md&#34;&gt;
            &lt;h2 id=&#34;complete-aria-roles-reference&#34;&gt;Complete ARIA roles reference&lt;/h2&gt;
&lt;p&gt;The following roles are supported and can be used with &lt;code&gt;getByRole()&lt;/code&gt;, organized by category:&lt;/p&gt;
&lt;h3 id=&#34;widgets--inputs&#34;&gt;Widgets &amp;amp; Inputs&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;button&lt;/code&gt; - Buttons and clickable elements&lt;/li&gt;
&lt;li&gt;&lt;code&gt;checkbox&lt;/code&gt; - Checkable boxes that can be on/off&lt;/li&gt;
&lt;li&gt;&lt;code&gt;combobox&lt;/code&gt; - Editable drop-down menu combining input and list box&lt;/li&gt;
&lt;li&gt;&lt;code&gt;listbox&lt;/code&gt; - Container for selectable list options&lt;/li&gt;
&lt;li&gt;&lt;code&gt;menu&lt;/code&gt; - Menu of actions or navigation&lt;/li&gt;
&lt;li&gt;&lt;code&gt;menubar&lt;/code&gt; - Container for top-level menus&lt;/li&gt;
&lt;li&gt;&lt;code&gt;menuitem&lt;/code&gt; - Option within a menu&lt;/li&gt;
&lt;li&gt;&lt;code&gt;menuitemcheckbox&lt;/code&gt; - Checkable menu item&lt;/li&gt;
&lt;li&gt;&lt;code&gt;menuitemradio&lt;/code&gt; - Mutually exclusive menu item&lt;/li&gt;
&lt;li&gt;&lt;code&gt;meter&lt;/code&gt; - Scalar measurement within a known range&lt;/li&gt;
&lt;li&gt;&lt;code&gt;option&lt;/code&gt; - Selectable option in a list box or combo box&lt;/li&gt;
&lt;li&gt;&lt;code&gt;progressbar&lt;/code&gt; - Progress indicator of an operation&lt;/li&gt;
&lt;li&gt;&lt;code&gt;radio&lt;/code&gt; - Single-select option in a group&lt;/li&gt;
&lt;li&gt;&lt;code&gt;radiogroup&lt;/code&gt; - Grouping of related radio buttons&lt;/li&gt;
&lt;li&gt;&lt;code&gt;scrollbar&lt;/code&gt; - Control for scrolling content&lt;/li&gt;
&lt;li&gt;&lt;code&gt;searchbox&lt;/code&gt; - Text field for search input&lt;/li&gt;
&lt;li&gt;&lt;code&gt;separator&lt;/code&gt; - Divider that separates content or controls&lt;/li&gt;
&lt;li&gt;&lt;code&gt;slider&lt;/code&gt; - Adjustable value control within a range&lt;/li&gt;
&lt;li&gt;&lt;code&gt;spinbutton&lt;/code&gt; - Numeric input with increment/decrement controls&lt;/li&gt;
&lt;li&gt;&lt;code&gt;status&lt;/code&gt; - Advisory status information (non-alert)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;switch&lt;/code&gt; - On/off toggle control&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tab&lt;/code&gt; - A tab in a tabbed interface&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tablist&lt;/code&gt; - Container for a set of tabs&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tabpanel&lt;/code&gt; - Content panel associated with a tab&lt;/li&gt;
&lt;li&gt;&lt;code&gt;textbox&lt;/code&gt; - Input field for free-form text&lt;/li&gt;
&lt;li&gt;&lt;code&gt;timer&lt;/code&gt; - Running time display that updates&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toolbar&lt;/code&gt; - Group of interactive controls&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tooltip&lt;/code&gt; - Contextual help popup&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tree&lt;/code&gt; - Hierarchical list of items&lt;/li&gt;
&lt;li&gt;&lt;code&gt;treeitem&lt;/code&gt; - Item in a tree&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;tables--grids&#34;&gt;Tables &amp;amp; Grids&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;table&lt;/code&gt; - Tabular data with rows and columns.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;rowgroup&lt;/code&gt; - Section that groups rows. For example, &lt;code&gt;thead&lt;/code&gt;, &lt;code&gt;tbody&lt;/code&gt;, &lt;code&gt;tfoot&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;row&lt;/code&gt; - A row of cells within a table or grid.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;rowheader&lt;/code&gt; - Header cell for a row.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;columnheader&lt;/code&gt; - Header cell for a column.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;cell&lt;/code&gt; - Data cell in a table.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;grid&lt;/code&gt; - Interactive, tabular widget, such as a spreadsheet.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;gridcell&lt;/code&gt; - Cell within a grid.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;treegrid&lt;/code&gt; - Tree-structured grid with expandable rows.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;document-structure--semantics&#34;&gt;Document Structure &amp;amp; Semantics&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;article&lt;/code&gt; - Self-contained composition (article)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;blockquote&lt;/code&gt; - Quotation from another source&lt;/li&gt;
&lt;li&gt;&lt;code&gt;caption&lt;/code&gt; - Caption for a figure, table, or media&lt;/li&gt;
&lt;li&gt;&lt;code&gt;code&lt;/code&gt; - Fragment of computer code&lt;/li&gt;
&lt;li&gt;&lt;code&gt;definition&lt;/code&gt; - Definition of a term&lt;/li&gt;
&lt;li&gt;&lt;code&gt;deletion&lt;/code&gt; - Content removed from a document&lt;/li&gt;
&lt;li&gt;&lt;code&gt;directory&lt;/code&gt; - List of references&lt;/li&gt;
&lt;li&gt;&lt;code&gt;document&lt;/code&gt; - Standalone document content&lt;/li&gt;
&lt;li&gt;&lt;code&gt;emphasis&lt;/code&gt; - Content with emphatic stress&lt;/li&gt;
&lt;li&gt;&lt;code&gt;feed&lt;/code&gt; - Stream of articles or entries&lt;/li&gt;
&lt;li&gt;&lt;code&gt;figure&lt;/code&gt; - Figure with optional caption&lt;/li&gt;
&lt;li&gt;&lt;code&gt;generic&lt;/code&gt; - Generic container with no specific semantics&lt;/li&gt;
&lt;li&gt;&lt;code&gt;img&lt;/code&gt; - Image treated as a single graphic&lt;/li&gt;
&lt;li&gt;&lt;code&gt;insertion&lt;/code&gt; - Content added to a document&lt;/li&gt;
&lt;li&gt;&lt;code&gt;link&lt;/code&gt; - Hyperlink to another location&lt;/li&gt;
&lt;li&gt;&lt;code&gt;list&lt;/code&gt; - List of items&lt;/li&gt;
&lt;li&gt;&lt;code&gt;listitem&lt;/code&gt; - A single item within a list&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mark&lt;/code&gt; - Highlighted or marked content&lt;/li&gt;
&lt;li&gt;&lt;code&gt;marquee&lt;/code&gt; - Scrolling region of text&lt;/li&gt;
&lt;li&gt;&lt;code&gt;math&lt;/code&gt; - Mathematical expression&lt;/li&gt;
&lt;li&gt;&lt;code&gt;note&lt;/code&gt; - An aside or annotation&lt;/li&gt;
&lt;li&gt;&lt;code&gt;none&lt;/code&gt; - No semantic role; remove semantics&lt;/li&gt;
&lt;li&gt;&lt;code&gt;paragraph&lt;/code&gt; - Paragraph of text&lt;/li&gt;
&lt;li&gt;&lt;code&gt;presentation&lt;/code&gt; - Presentational only; ignore semantics&lt;/li&gt;
&lt;li&gt;&lt;code&gt;strong&lt;/code&gt; - Content of strong importance&lt;/li&gt;
&lt;li&gt;&lt;code&gt;subscript&lt;/code&gt; - Subscripted text&lt;/li&gt;
&lt;li&gt;&lt;code&gt;superscript&lt;/code&gt; - Superscripted text&lt;/li&gt;
&lt;li&gt;&lt;code&gt;term&lt;/code&gt; - A term being defined&lt;/li&gt;
&lt;li&gt;&lt;code&gt;time&lt;/code&gt; - A time or date&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;landmarks--regions&#34;&gt;Landmarks &amp;amp; Regions&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;banner&lt;/code&gt; - Site header landmark&lt;/li&gt;
&lt;li&gt;&lt;code&gt;complementary&lt;/code&gt; - Complementary content (sidebar)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;contentinfo&lt;/code&gt; - Page footer information&lt;/li&gt;
&lt;li&gt;&lt;code&gt;form&lt;/code&gt; - Region containing a form&lt;/li&gt;
&lt;li&gt;&lt;code&gt;main&lt;/code&gt; - Main content landmark&lt;/li&gt;
&lt;li&gt;&lt;code&gt;navigation&lt;/code&gt; - Navigation region of links&lt;/li&gt;
&lt;li&gt;&lt;code&gt;region&lt;/code&gt; - Generic region of the page&lt;/li&gt;
&lt;li&gt;&lt;code&gt;search&lt;/code&gt; - Search region&lt;/li&gt;
&lt;li&gt;&lt;code&gt;application&lt;/code&gt; - Application container widget&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;usage-examples-by-category&#34;&gt;Usage Examples by Category&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Form Testing:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- md-k6:skip --&gt;
&lt;!-- eslint-skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;// Text inputs
await page.getByRole(&amp;#39;textbox&amp;#39;, { name: &amp;#39;Email&amp;#39; }).fill(&amp;#39;user@example.com&amp;#39;);
await page.getByRole(&amp;#39;searchbox&amp;#39;, { name: &amp;#39;Search products&amp;#39; }).fill(&amp;#39;laptop&amp;#39;);

// Selections
await page.getByRole(&amp;#39;checkbox&amp;#39;, { name: &amp;#39;Agree to terms&amp;#39; }).check();
await page.getByRole(&amp;#39;radio&amp;#39;, { name: &amp;#39;Standard shipping&amp;#39; }).check();
await page.getByRole(&amp;#39;combobox&amp;#39;, { name: &amp;#39;Country&amp;#39; }).selectOption(&amp;#39;US&amp;#39;);

// Interactive controls
await page.getByRole(&amp;#39;slider&amp;#39;, { name: &amp;#39;Volume&amp;#39; }).fill(&amp;#39;75&amp;#39;);
await page.getByRole(&amp;#39;switch&amp;#39;, { name: &amp;#39;Enable notifications&amp;#39; }).click();&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Navigation Testing:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- md-k6:skip --&gt;
&lt;!-- eslint-skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;// Tabs
await page.getByRole(&amp;#39;tab&amp;#39;, { name: &amp;#39;Overview&amp;#39; }).click();
await expect(page.getByRole(&amp;#39;tabpanel&amp;#39;, { name: &amp;#39;Overview&amp;#39; })).toBeVisible();&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Content Verification:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- md-k6:skip --&gt;
&lt;!-- eslint-skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;// Structure
await expect(page.getByRole(&amp;#39;article&amp;#39;)).toHaveCount(5);
await expect(page.getByRole(&amp;#39;heading&amp;#39;, { level: 1 })).toHaveText(&amp;#39;Welcome&amp;#39;);

// Status and feedback
await expect(page.getByRole(&amp;#39;alert&amp;#39;)).toHaveText(&amp;#39;Form submitted successfully&amp;#39;);
await expect(page.getByRole(&amp;#39;status&amp;#39;)).toHaveText(&amp;#39;3 items selected&amp;#39;);&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Prefer role-based selection&lt;/strong&gt;: &lt;code&gt;getByRole()&lt;/code&gt; is the preferred method for locating elements as it closely mirrors how users and assistive technology interact with your page.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use accessible names&lt;/strong&gt;: Always try to use the &lt;code&gt;name&lt;/code&gt; option to make your tests more specific and reliable.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consider accessibility&lt;/strong&gt;: Using &lt;code&gt;getByRole()&lt;/code&gt; encourages better accessibility practices in your application by ensuring elements have proper ARIA roles.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

        
&lt;h2 id=&#34;related&#34;&gt;Related&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyalttext/&#34;&gt;frameLocator.getByAltText()&lt;/a&gt; - Locate by alt text&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbylabel/&#34;&gt;frameLocator.getByLabel()&lt;/a&gt; - Locate by form labels&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyplaceholder/&#34;&gt;frameLocator.getByPlaceholder()&lt;/a&gt; - Locate by placeholder text&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytestid/&#34;&gt;frameLocator.getByTestId()&lt;/a&gt; - Locate by test ID&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytext/&#34;&gt;frameLocator.getByText()&lt;/a&gt; - Locate by text content&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytitle/&#34;&gt;frameLocator.getByTitle()&lt;/a&gt; - Locate by title attribute&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;div data-shared="browser/getby-apis/getbyrole-spec.md">
&lt;h1 id="getbyrolerole-options">getByRole(role[, options])&lt;/h1>
&lt;p>Returns a locator for elements with the specified ARIA role. This is the preferred way to locate elements as it most closely resembles how users and assistive technology perceive the page.&lt;/p></description></item><item><title>getByTestId(testId)</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytestid/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytestid/</guid><content><![CDATA[

&lt;div data-shared=&#34;browser/getby-apis/getbytestid-spec.md&#34;&gt;
            &lt;h1 id=&#34;getbytestidtestid&#34;&gt;getByTestId(testId)&lt;/h1&gt;
&lt;p&gt;Returns a locator for elements with the specified test ID attribute. This method is designed for robust test automation by locating elements using dedicated test identifiers that are independent of the visual appearance or content changes. Currently it can only work with the &lt;code&gt;data-testid&lt;/code&gt; attribute.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;testId&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string | RegExp&lt;/td&gt;
              &lt;td&gt;-&lt;/td&gt;
              &lt;td&gt;Required. The test ID value to search for. Searches for the &lt;code&gt;data-testid&lt;/code&gt; attribute. Can be a string for exact match or a RegExp for pattern matching.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/locator/&#34;&gt;Locator&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A locator object that can be used to interact with the elements matching the specified test ID.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;basic-test-id-usage&#34;&gt;Basic test ID usage&lt;/h3&gt;
&lt;p&gt;Locate and interact with elements using test IDs:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    browser: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    const iframeHTML = `
      &amp;lt;input type=&amp;#34;text&amp;#34; data-testid=&amp;#34;username&amp;#34;&amp;gt;
      &amp;lt;input type=&amp;#34;text&amp;#34; data-testid=&amp;#34;email&amp;#34;&amp;gt;
      &amp;lt;button data-testid=&amp;#34;submit-button&amp;#34;&amp;gt;Submit&amp;lt;/button&amp;gt;
    `;

    await page.setContent(`
      &amp;lt;iframe id=&amp;#34;my_frame&amp;#34; src=&amp;#34;data:text/html,${encodeURIComponent(iframeHTML)}&amp;#34;&amp;gt;&amp;lt;/iframe&amp;gt;
    `);

    const frameLocator = page.locator(&amp;#34;#my_frame&amp;#34;).contentFrame();
    await frameLocator.getByTestId(&amp;#39;username&amp;#39;).fill(&amp;#39;FirstLast&amp;#39;);
    await frameLocator.getByTestId(&amp;#39;email&amp;#39;).fill(&amp;#39;firstlast@example.com&amp;#39;);
    await frameLocator.getByTestId(&amp;#39;submit-button&amp;#39;).click();
  } finally {
    await page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div data-shared=&#34;browser/getby-apis/getbytestid-tips.md&#34;&gt;
            &lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Stable identifiers&lt;/strong&gt;: Use meaningful, stable test IDs that won&amp;rsquo;t change with refactoring or content updates.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hierarchical naming&lt;/strong&gt;: Use consistent naming conventions like &lt;code&gt;user-profile-edit-btn&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Avoid duplicates&lt;/strong&gt;: Ensure test IDs are unique within the page to prevent ambiguity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Strategic placement&lt;/strong&gt;: Add test IDs to key interactive elements and components that are frequently tested.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Team coordination&lt;/strong&gt;: Establish test ID conventions with your development team to ensure consistency.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

        
&lt;h2 id=&#34;related&#34;&gt;Related&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyrole/&#34;&gt;frameLocator.getByRole()&lt;/a&gt; - Locate by ARIA role&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyalttext/&#34;&gt;frameLocator.getByAltText()&lt;/a&gt; - Locate by alt text&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbylabel/&#34;&gt;frameLocator.getByLabel()&lt;/a&gt; - Locate by form labels&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyplaceholder/&#34;&gt;frameLocator.getByPlaceholder()&lt;/a&gt; - Locate by placeholder text&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytext/&#34;&gt;frameLocator.getByText()&lt;/a&gt; - Locate by text content&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytitle/&#34;&gt;frameLocator.getByTitle()&lt;/a&gt; - Locate by title attribute&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;div data-shared="browser/getby-apis/getbytestid-spec.md">
&lt;h1 id="getbytestidtestid">getByTestId(testId)&lt;/h1>
&lt;p>Returns a locator for elements with the specified test ID attribute. This method is designed for robust test automation by locating elements using dedicated test identifiers that are independent of the visual appearance or content changes. Currently it can only work with the &lt;code>data-testid&lt;/code> attribute.&lt;/p></description></item><item><title>getByText(text[, options])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytext/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytext/</guid><content><![CDATA[

&lt;div data-shared=&#34;browser/getby-apis/getbytext-spec.md&#34;&gt;
            &lt;h1 id=&#34;getbytexttext-options&#34;&gt;getByText(text[, options])&lt;/h1&gt;
&lt;p&gt;Returns a locator for elements containing the specified text. This method finds elements by their visible text content, making it ideal for locating user-facing content like buttons, links, headings, and other text elements.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;text&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string | RegExp&lt;/td&gt;
              &lt;td&gt;-&lt;/td&gt;
              &lt;td&gt;Required. The text content to search for. Can be a string for exact match or a RegExp for pattern matching.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;object&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.exact&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Whether to match the text exactly with case sensitivity. When &lt;code&gt;true&lt;/code&gt;, performs a case-sensitive match.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/locator/&#34;&gt;Locator&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A locator object that can be used to interact with the elements containing the specified text.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Find and click elements by their visible text:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    browser: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    await page.setContent(`
      &amp;lt;iframe id=&amp;#34;my_frame&amp;#34; src=&amp;#34;https://quickpizza.grafana.com&amp;#34; width=&amp;#34;50%&amp;#34; height=&amp;#34;50%&amp;#34;&amp;gt;&amp;lt;/iframe&amp;gt;
    `);

    const frameLocator = page.locator(&amp;#39;#my_frame&amp;#39;).contentFrame();
    await frameLocator.getByText(&amp;#39;Pizza, Please!&amp;#39;).click();

    const noThanksBtn = frameLocator.getByText(&amp;#39;No thanks&amp;#39;);
    await noThanksBtn.click();
  } finally {
    await page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div data-shared=&#34;browser/getby-apis/getbytext-tips.md&#34;&gt;
            &lt;h2 id=&#34;text-matching-behavior&#34;&gt;Text matching behavior&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Whitespace normalization&lt;/strong&gt;: Text matching automatically normalizes whitespace, meaning:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Multiple spaces become single spaces&lt;/li&gt;
&lt;li&gt;Line breaks become spaces&lt;/li&gt;
&lt;li&gt;Leading and trailing whitespace is ignored&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Consider the following DOM structure:&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;
&lt;!-- eslint-skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;HTML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-html&#34;&gt;&amp;lt;div&amp;gt;Hello &amp;lt;span&amp;gt;world&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;Hello&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can locate by text substring, exact string, or a regular expression:&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;
&lt;!-- eslint-skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;js&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-js&#34;&gt;// Matches &amp;lt;span&amp;gt;
page.getByText(&amp;#39;world&amp;#39;);
// Matches first &amp;lt;div&amp;gt;
page.getByText(&amp;#39;Hello world&amp;#39;);
// Matches second &amp;lt;div&amp;gt;
page.getByText(&amp;#39;Hello&amp;#39;, { exact: true });
// Matches both &amp;lt;div&amp;gt;s
page.getByText(/Hello/);
// Matches second &amp;lt;div&amp;gt;
page.getByText(/^hello$/i);&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;common-use-cases&#34;&gt;Common use cases&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Button interactions&lt;/strong&gt;: Submit, Cancel, Delete, Edit buttons&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Navigation&lt;/strong&gt;: Menu items, breadcrumbs, pagination links&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Content verification&lt;/strong&gt;: Success messages, error messages, headings&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Form interactions&lt;/strong&gt;: Checkbox labels, radio button options&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Status indicators&lt;/strong&gt;: Active, Inactive, Pending states&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;User-focused testing&lt;/strong&gt;: Using &lt;code&gt;getByText()&lt;/code&gt; ensures your tests interact with content as users see it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Avoid brittle text&lt;/strong&gt;: Be cautious with exact text that might change frequently (like dates, counts, or user-generated content).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use meaningful text&lt;/strong&gt;: Prefer descriptive button text and labels over generic terms like &amp;ldquo;Click here&amp;rdquo; or &amp;ldquo;Button&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Handle dynamic content&lt;/strong&gt;: Use regular expressions for text that contains variable parts (timestamps, user names, counts).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consider accessibility&lt;/strong&gt;: Text-based selection encourages better accessibility practices in your application.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Internationalization&lt;/strong&gt;: For multi-language applications, consider using test IDs or roles instead of text for critical interactions.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

        
&lt;h2 id=&#34;related&#34;&gt;Related&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyrole/&#34;&gt;frameLocator.getByRole()&lt;/a&gt; - Locate by ARIA role&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyalttext/&#34;&gt;frameLocator.getByAltText()&lt;/a&gt; - Locate by alt text&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbylabel/&#34;&gt;frameLocator.getByLabel()&lt;/a&gt; - Locate by form labels&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyplaceholder/&#34;&gt;frameLocator.getByPlaceholder()&lt;/a&gt; - Locate by placeholder text&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytestid/&#34;&gt;frameLocator.getByTestId()&lt;/a&gt; - Locate by test ID&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytitle/&#34;&gt;frameLocator.getByTitle()&lt;/a&gt; - Locate by title attribute&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;div data-shared="browser/getby-apis/getbytext-spec.md">
&lt;h1 id="getbytexttext-options">getByText(text[, options])&lt;/h1>
&lt;p>Returns a locator for elements containing the specified text. This method finds elements by their visible text content, making it ideal for locating user-facing content like buttons, links, headings, and other text elements.&lt;/p></description></item><item><title>getByTitle(title[, options])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytitle/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytitle/</guid><content><![CDATA[

&lt;div data-shared=&#34;browser/getby-apis/getbytitle-spec.md&#34;&gt;
            &lt;h1 id=&#34;getbytitletitle-options&#34;&gt;getByTitle(title[, options])&lt;/h1&gt;
&lt;p&gt;Returns a locator for elements with the specified &lt;code&gt;title&lt;/code&gt; attribute. This method is useful for locating elements that use the &lt;code&gt;title&lt;/code&gt; attribute to provide additional information, tooltips, or accessibility context.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;title&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;string | RegExp&lt;/td&gt;
              &lt;td&gt;-&lt;/td&gt;
              &lt;td&gt;Required. The title text to search for. Can be a string for exact match or a RegExp for pattern matching.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;object&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;options.exact&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;boolean&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Whether to match the title text exactly with case sensitivity. When &lt;code&gt;true&lt;/code&gt;, performs a case-sensitive match.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;returns&#34;&gt;Returns&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/locator/&#34;&gt;Locator&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A locator object that can be used to interact with the elements matching the specified title attribute.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/div&gt;

        
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Find and interact with elements by their title attribute:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    browser: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    const iframeHTML = `
      &amp;lt;button title=&amp;#34;Hello World&amp;#34;&amp;gt;Hi&amp;lt;/button&amp;gt;
      &amp;lt;select title=&amp;#34;Favorite Color&amp;#34;&amp;gt;
        &amp;lt;option value=&amp;#34;Red&amp;#34;&amp;gt;Red&amp;lt;/option&amp;gt;
        &amp;lt;option value=&amp;#34;Green&amp;#34;&amp;gt;Green&amp;lt;/option&amp;gt;
        &amp;lt;option value=&amp;#34;Blue&amp;#34;&amp;gt;Blue&amp;lt;/option&amp;gt;
      &amp;lt;/select&amp;gt;
      &amp;lt;input type=&amp;#34;checkbox&amp;#34; title=&amp;#34;Check me&amp;#34;&amp;gt;
    `;

    await page.setContent(`
      &amp;lt;iframe id=&amp;#34;my_frame&amp;#34; src=&amp;#34;data:text/html,${encodeURIComponent(iframeHTML)}&amp;#34;&amp;gt;&amp;lt;/iframe&amp;gt;
    `);

    const frameLocator = page.locator(&amp;#34;#my_frame&amp;#34;).contentFrame();

    await frameLocator.getByTitle(&amp;#39;Hello World&amp;#39;).click();

    await frameLocator.getByTitle(&amp;#39;Favorite Color&amp;#39;).selectOption(&amp;#39;Red&amp;#39;);

    await frameLocator.getByTitle(&amp;#39;Check me&amp;#39;).check();
  } finally {
    await page.close();
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div data-shared=&#34;browser/getby-apis/getbytitle-tips.md&#34;&gt;
            &lt;h2 id=&#34;common-use-cases&#34;&gt;Common use cases&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;User interface controls:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Toolbar buttons and action items&lt;/li&gt;
&lt;li&gt;Navigation controls (previous/next, pagination)&lt;/li&gt;
&lt;li&gt;Media player controls&lt;/li&gt;
&lt;li&gt;Menu and drop-down triggers&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Informational elements:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Help icons and tooltips&lt;/li&gt;
&lt;li&gt;Status indicators and badges&lt;/li&gt;
&lt;li&gt;Progress indicators&lt;/li&gt;
&lt;li&gt;Warning and error messages&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Accessibility support:&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Screen reader descriptions&lt;/li&gt;
&lt;li&gt;Alternative text for complex elements&lt;/li&gt;
&lt;li&gt;Context-sensitive help&lt;/li&gt;
&lt;li&gt;Form field explanations&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Meaningful titles&lt;/strong&gt;: Ensure title attributes provide clear, helpful information about the element&amp;rsquo;s purpose or content.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Accessibility compliance&lt;/strong&gt;: Use titles to enhance accessibility, especially for elements that might not have clear visual labels.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Avoid redundancy&lt;/strong&gt;: Don&amp;rsquo;t duplicate visible text in the title attribute unless providing additional context.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic content&lt;/strong&gt;: When testing applications with changing title content, use flexible matching patterns or regular expressions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tooltip testing&lt;/strong&gt;: Remember that title attributes often create tooltips on hover, which can be useful for UI testing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Internationalization&lt;/strong&gt;: Consider that title text may change in different language versions of your application.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

        
&lt;h2 id=&#34;related&#34;&gt;Related&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyrole/&#34;&gt;frameLocator.getByRole()&lt;/a&gt; - Locate by ARIA role&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyalttext/&#34;&gt;frameLocator.getByAltText()&lt;/a&gt; - Locate by alt text&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbylabel/&#34;&gt;frameLocator.getByLabel()&lt;/a&gt; - Locate by form labels&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbyplaceholder/&#34;&gt;frameLocator.getByPlaceholder()&lt;/a&gt; - Locate by placeholder text&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytestid/&#34;&gt;frameLocator.getByTestId()&lt;/a&gt; - Locate by test ID&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/getbytext/&#34;&gt;frameLocator.getByText()&lt;/a&gt; - Locate by visible text&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;div data-shared="browser/getby-apis/getbytitle-spec.md">
&lt;h1 id="getbytitletitle-options">getByTitle(title[, options])&lt;/h1>
&lt;p>Returns a locator for elements with the specified &lt;code>title&lt;/code> attribute. This method is useful for locating elements that use the &lt;code>title&lt;/code> attribute to provide additional information, tooltips, or accessibility context.&lt;/p></description></item><item><title>locator(selector[, options])</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/locator/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-browser/framelocator/locator/</guid><content><![CDATA[&lt;h1 id=&#34;locatorselector-options&#34;&gt;locator(selector[, options])&lt;/h1&gt;
&lt;p&gt;The method returns an element&amp;rsquo;s 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/locator/&#34;&gt;Locator&lt;/a&gt;. Locators resolve to the element when the action takes place, which means locators can span over navigations where the underlying DOM changes.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Parameter&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;selector&lt;/td&gt;
              &lt;td&gt;string&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;&#39;&#39;&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A selector to use when resolving a DOM element.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;options&lt;/td&gt;
              &lt;td&gt;object&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;options.hasText&lt;/td&gt;
              &lt;td&gt;string or RegExp&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Matches only elements that contain the specified text. String or regular expression. Optional.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;options.hasNotText&lt;/td&gt;
              &lt;td&gt;string or RegExp&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Matches only elements that do not contain the specified text. String or regular expression. Optional.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;returns&#34;&gt;Returns&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-browser/locator/&#34;&gt;Locator&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;The element&amp;rsquo;s &lt;code&gt;Locator&lt;/code&gt; associated with the frame.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;

export const options = {
  scenarios: {
    ui: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  await page.setContent(`&amp;lt;iframe src=&amp;#39;https://quickpizza.grafana.com&amp;#39;&amp;gt;&amp;lt;/iframe&amp;gt;`);

  // Get a locator for an iframe element
  const frameLocator = page.locator(&amp;#39;iframe&amp;#39;).contentFrame();

  // Create a locator within the frame with text filtering options
  const submitButton = frameLocator.locator(&amp;#39;button&amp;#39;, { hasText: &amp;#39;Pizza, Please!&amp;#39; });
  await submitButton.click();
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="locatorselector-options">locator(selector[, options])&lt;/h1>
&lt;p>The method returns an element&amp;rsquo;s
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-browser/locator/">Locator&lt;/a>. Locators resolve to the element when the action takes place, which means locators can span over navigations where the underlying DOM changes.&lt;/p></description></item></channel></rss>