问题
When I need to wait for an element to become visible I can simple call the selector as a function like this:
await element.with({ visibilityCheck: true })();
But how can I wait for an element to disappear?
回答1:
To wait for an element to disappear you can use our built-in waiting mechanism for assertions. Please see the documentation for more information on how it works.
import { Selector } from 'testcafe';
fixture `fixture`
.page `http://localhost/testcafe/`;
test('test 2', async t => {
//step 1
//wait for the element to disappear (assertion with timeout)
await t.expect(Selector('element').exists).notOk({ timeout: 5000 });
//next steps
});
Or you can use the ClientFunction:
import { ClientFunction } from 'testcafe';
fixture `fixture`
.page `http://localhost/testcafe/`;
const elementVisibilityWatcher = ClientFunction(() => {
return new Promise(resolve => {
var interval = setInterval(() => {
if (document.querySelector('element'))
return;
clearInterval(interval);
resolve();
}, 100);
});
});
test('test 1', async t => {
//step 1
//wait for the element to disappear
await elementVisibilityWatcher();
//next steps
});
来源:https://stackoverflow.com/questions/54970442/how-to-wait-for-an-element-to-disappear-in-testcafe