Page.keyboard attribute null or undefined

After updating to the 0.8.0 version of the xk6-browser the page class doesn’t seem to contain the keyboard attribute.

How to reproduce:

import { chromium } from 'k6/x/browser';
import { sleep } from 'k6';


export default async function () {

  const browser = chromium.launch({ headless: false, timeout: "10m" });
  const page = browser.newPage();
  
  
  page.goto("https://www.bing.com/", { waitUntil: 'networkidle' })
  sleep(3)
  const searchBar = page.$$('input[type="search"]')[0]
  searchBar.click()
  await searchBar.type("Banana")
  sleep(3)
  page.keyboard.press("Enter")

  sleep(3)
  page.close()
  browser.close()


}

Result

Hi @george.l !

The problem is in the line:

page.keyboard.press("Enter")

As keyboard is not a property of page for xk6-browser. In this case you should use the locator that you already obtained for the searchbar. Like:

export default async function () {

  const browser = chromium.launch({ headless: false, timeout: "10m" });
  const page = browser.newPage();

  await page.goto("https://www.bing.com/", { waitUntil: 'networkidle' });
  sleep(3)
  const searchBar = page.$$('input[type="search"]')[0];
  await searchBar.click();
  searchBar.type("Banana");
  sleep(3);
  searchBar.press("Enter");

  sleep(3)
  page.close()
  browser.close()
}

Let me know if that works.
Regards.

1 Like

Thanks again Daniel, it works. But I thought both mouse and keyboard were properties of page.
https://k6.io/docs/javascript-api/xk6-browser/api/page/
In any case is there a workaround for mouse too? Because I’m encountering the same problem. I’m trying to use a slider so locator.click() is not enough. I would like to use the mouse to click on a specific point of the locator’s bounding box

You are absolutely right @george.l, apologies for the confusion, we have realized that this is a bug introduced in the latest version after changes were made to accommodate the merge of the extension with k6.

We have created an issue and we will try to fix it soon so the first version of k6 that includes xk6-browser works as expected. You can follow the progress on the issue here.

Thank you for helping us detect this.

2 Likes