Closed tom-miseur closed 2 years ago
@tom-miseur I have a fix for a bug in waitForSelector
. I discovered and fixed this issue when recording the obscon demo :)
The fix is basically changing https://github.com/grafana/xk6-browser/blob/main/common/element_handle.go#L886 to say rt.ToValue(opts.Timeout.Milliseconds()),
, I have a PR with test case that I'll get around to pushing tomorrow hopefully 🙂 The effect of the current code is no waiting for the element to even attach (if not attached).
The page.waitForLoadState
function doesn't actually work reliably as it'd need to be async to do so, as the time window between the click
and the call to waitForLoadState
could actually see the specified event fire and thus when waitForLoadState
is called it waits forever, or rather until timeout. So in Playwright you'd first call waitForLoadState
, get a promise back, call the action (click
in this case) and then await the promise.
The following script causes
panic: interface conversion: interface {} is nil, not *common.ElementHandle
during the call topage.waitForSelector("li.design-tile");
:Uncommenting
page.waitForLoadState('networkidle')
allows the script to proceed (although it eventually fails withpanic: send on closed channel
as per #49).The only exception I'm expecting here is a timeout in case the selector was unsuccessful.
I think what might be happening is that the auto-wait on
elem.click();
is not waiting long enough for the page to even change (the site is very slow at switching), and so we attempt topage.waitForSelector("li.design-tile")
on a page/element that's about to be "detached".