page.evaluate (mentioned in : Click elements within an iframe - #9 by inancgumus) did not work, but I found another way to click a checkbox within an iframe but now I am getting another error when I get back to page and click submit button on the page.
Below you can see my code:
import {browser} from 'k6/experimental/browser';
export const options = {
scenarios: {
ui: {
// mandatory fields; executor, options-->browser-->type
executor: 'shared-iterations',
vus: 1,
iterations: 1,
options: {
browser: {
type: 'chromium',
},
},
},
}
}
export default async function () {
const page = browser.newPage();
try {
await page.goto('*************/my-dashboard#/sign-in', {waitUntil: 'networkidle'});
page.screenshot({path: 'screenshot.png'});
await page.locator('button[id="**********"]').click();
await page.locator('input[type="email"]').type('*******@mailinator.com');
await page.locator('input[type="password"]').type('******');
let frames = await page.frames();
for (const frame of frames) {
if (frame.title() === 'reCAPTCHA' && frame.name().startsWith('a')) {
await frame.waitForLoadState();
const spanElement = frame.locator('#recaptcha-anchor');
spanElement.focus();
spanElement.dispatchEvent('click');
break;
}
}
// not clicking the submit button and getting an error
await page.locator("button[type='submit']").click();
} finally {
page.close();
}
}
The error I am getting:
panic: GoError: dispose: canceled
running (00m14.2s), 1/1 VUs, 0 complete and 0 interrupted iterations
goroutine 130 [running]:----------------------] 1 VUs 00m14.2s/10m0s 0/1 shared iters
go.k6.io/k6/js/common.Throw(...)
go.k6.io/k6/js/common/util.go:20
github.com/grafana/xk6-browser/k6ext.Panic.func1(0x207f9c0?, {0xc000302d10?, 0x2112b01?, 0xc000d5eb40?})
github.com/grafana/xk6-browser@v1.0.2/k6ext/panic.go:35 +0x74
github.com/grafana/xk6-browser/k6ext.sharedPanic({0x2583340, 0xc002629900}, 0xc002479a30, {0xc000302d10?, 0x1, 0x1})
github.com/grafana/xk6-browser@v1.0.2/k6ext/panic.go:64 +0x256
github.com/grafana/xk6-browser/k6ext.Panic({0x2583340?, 0xc002629900?}, {0x22a440f?, 0xc000310490?}, {0xc000302d10?, 0xc0003104a0?, 0x2008000?})
github.com/grafana/xk6-browser@v1.0.2/k6ext/panic.go:37 +0x5a
github.com/grafana/xk6-browser/common.(*BaseJSHandle).Dispose(0xc002086dc0)
github.com/grafana/xk6-browser@v1.0.2/common/js_handle.go:70 +0x9f
github.com/grafana/xk6-browser/common.(*Frame).detach(0xc0026b81c0)
github.com/grafana/xk6-browser@v1.0.2/common/frame.go:196 +0x14a
github.com/grafana/xk6-browser/common.(*FrameManager).removeFramesRecursively(0xc002798180, 0xc00125d520?)
github.com/grafana/xk6-browser@v1.0.2/common/frame_manager.go:415 +0x29f
github.com/grafana/xk6-browser/common.(*FrameManager).frameDetached(0xc002798180, {0xc00125d520, 0x20}, {0x229bd17, 0x6})
github.com/grafana/xk6-browser@v1.0.2/common/frame_manager.go:186 +0x151
github.com/grafana/xk6-browser/common.(*FrameSession).onFrameDetached(0xc00023d970, {0xc00125d520, 0x20}, {0x229bd17, 0x6})
github.com/grafana/xk6-browser@v1.0.2/common/frame_session.go:710 +0x177
github.com/grafana/xk6-browser/common.(*FrameSession).initEvents.func1()
github.com/grafana/xk6-browser@v1.0.2/common/frame_session.go:237 +0x596
created by github.com/grafana/xk6-browser/common.(*FrameSession).initEvents in goroutine 42
github.com/grafana/xk6-browser@v1.0.2/common/frame_session.go:211 +0x193