Testcafe: Is there a way to stop page loading further after the targetted element is loaded in dom?

Viewed 147

Is there a way to force the page to stop loading any further when one of the required DOM elements has been loaded?

Similar to pressing the escape button on the browser to stop the page loading any further, is there a way to do this in Testcafe please?

1 Answers

I think the following should work:

const cancelLoading = ClientFunction(() => window.stop());

then whenever you call await cancelLoading(), the page should stop loading further. For example after you find an element:

const inputField = Selector('#just-an-example');
await t
  .expect(inputField.visible).ok()
await cancelLoading();
Related