An alert window (or a pop up window) cant be dismissed

I am new to K6 and trying to automate our login page using the browser. After we login and the dashboard page opens up we get an alert box stating how the company uses the cookies. This alert box does not let us continue with the other feature navigation. I tried almost everything possible, including disabling popup, using browser context, or using the alert box xpath to click on dismiss button but it wouldnt work. Do we have a solution for this?

Hi @t2sgreat,

Welcome to the forum!

We need to be able to replicate the issue to be able to assist you. Could you share the following:

  1. The test script, pointing to a publicly accessible website.
  2. Which OS you’re running k6 on.
  3. What version of k6 you’re using.

Cheers,
Ankur

import {chromium} from 'k6/experimental/browser';
import {check, sleep} from 'k6';
export default async function () {
    

    const browser = chromium.launch({
        headless: false,
        slowMo: '500ms',
        timeout: '30s',
    });
 

    const page = browser.newPage();


    try {

        await page.goto('', {waitUntil: 'networkidle'});
        sleep(2)

        page.locator('input[name="username"]').type('');
        const submitButton = page.locator('input[type="submit"]');
        await Promise.all([page.waitForNavigation(), submitButton.click()]);

        await page.fill('input[name="password"]', '')
        await submitButton.click()

        sleep(2)

        const locator = page.locator('.one-exiger-button')
        locator.click({force : true})
        sleep(5)

    } finally {
        page.close();
        browser.close();
    }
}

This is the code I am using and for obvious reason did not include URL, Pass, and Username. I have a screenshot down below shows what I am seeing when i login. And I need to click on ‘Accept’ button. I do not have a publicly facing example website in handy now but i am looking into one. I am using MAC OS Catalina 10.15.7. And K6 version is k6 v0.45.0 ((devel), go1.20.5, darwin/amd64)

Hi @ankur not sure if you have seen this previous message, but for a public facing alert box (like “The Internet”) its automatically clicks on the accept button. However, when a cookie related message appears it would not click on any button neither i can access the alert box. Any help will be appreciated.

Hi @t2sgreat,

Apologies for the delay in getting back to you.

I’ve found a cookie consent form on google.com, and working with XPath you should be able to accept all the cookies with:

    const btn = page.locator('//button[contains(.,"Accept all")]');
    await btn.click();

I was having issues trying to get it to work with //button[text()="Accept all"], but I found why here. Give it a try and let me know if that helps.

Here’s the full test if you’re insterested:

import { chromium } from 'k6/experimental/browser';

export default async function() {
  const browser = chromium.launch({
    headless: false,
  });
  const page = browser.newPage();
 
  try {
    await page.goto('https://google.com');

    const btn = page.locator('//button[contains(.,"Accept all")]');
    await btn.click();
  } finally {
    page.close();
  }
}

Cheers,
Ankur