-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
locator.waitFor
errors during a page navigation
#1472
Comments
I believe we need to run waitFor on the global context (i.e. use runtime.Evaluate, instead of runtime.CallFunction), but it's going to be difficult, and i'm not 100% sure since it's not easy to POC. There is an extremely horrible workaround 😅 Basically retry until it works, here's a POC PR to showcase the (terrible but working) idea. |
Retrying sounds fine to me :) |
I did get it to run on the global context but that didn't help. The following is a drop in replacement for the existing func (h *ElementHandle) waitForSelector(apiCtx context.Context, selector string, opts *FrameWaitForSelectorOptions) (*ElementHandle, error) {
parsedSelector, err := NewSelector(selector)
if err != nil {
return nil, err
}
b, _ := json.Marshal(parsedSelector)
fmt.Println(string(b))
fn := fmt.Sprintf(`
%s
const is = new InjectedScript();
return is.waitForSelector(%s, null, true, '%s', 'raf', %d);
`, injectedScriptSource, string(b), opts.State.String(), opts.Timeout.Milliseconds())
action := runtime.Evaluate(fn).
WithAwaitPromise(true)
result, exceptionDetails, err := action.Do(cdp.WithExecutor(h.ctx, h.session))
if err != nil {
return nil, fmt.Errorf("evaluating JS in global context: %w", err)
}
if exceptionDetails != nil {
return nil, fmt.Errorf("%s", parseExceptionDetails(exceptionDetails))
}
res := NewJSHandle(h.ctx, h.session, h.execCtx, h.frame, result, h.logger)
switch r := res.(type) {
case *ElementHandle:
return r, nil
default:
return nil, nil
}
} |
I've created #1501 so that we can work on the actual fix for this issue. |
Brief summary
When working with
locator.waitFor
, it will error causing the iteration to end early if a navigation occurs while thewaitFor
is waiting. This happens when we perform something like:xk6-browser version
NA
OS
NA
Chrome version
NA
Docker version and image (if applicable)
No response
Steps to reproduce the problem
NA
Expected behaviour
It should wait until the selector is found and not error and end the iteration if a navigation occurs while a
waitFor
is waiting.Actual behaviour
It errors with something like
Uncaught (in promise) waiting for "//div[text()=\"Sign in\"]": Inspected target navigated or closed
Tasks
waitFor
until it is success or retry count is 0 #1469The text was updated successfully, but these errors were encountered: