2

I'm using webdriverio and need to wait for an element to be in the viewport

So I tried

browser.waitUntil(async () => {
    const b = await link.isDisplayedInViewport()
    return b;
}, 5000, 'expected to be visible after 5s');

But somehow waitUntil wants a boolean not a Promise<boolean>

enter image description here

How can I fix this?

Update:

I use WebdriverIO in a NodeJs app as follows

const { remote } = require('webdriverio');

(async () => {
    const browser = await remote({
        logLevel: 'error',
        path: '/',
        capabilities: {
            browserName: 'chrome'
        }
    });

    await browser.url('https://example.com');

    const link = await browser.$('.special-link');
    const ok = await browser.waitUntil(async () => {
        const b = await link.isDisplayedInViewport()
        return b;
    }, 5000, 'expected to be visible after 5s');

    await link.click();

    const title = await browser.getTitle();
    console.log('Title was: ' + title);

    await browser.deleteSession();
})().catch((e) => console.error(e));

source

In the options is don't see anything about with or without async/await. Furthermore I don't use a testing framework!

Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333

2 Answers2

2

Sorry for the late answer. But if you are still looking for a solution, Please try this if you want to avoid aync/await

 get link() { return browser.element('.special-link'); }

 browser.waitUntil(() => this.link.isVisibleWithinViewport(), 20000, 'link not visible')
Balachander
  • 430
  • 1
  • 3
  • 15
0
const elementWaitingToBeDisplayed = $("some element locators")
elementWaitingToBeDisplayed.waitForDisplayed(10000, false) 

If you set the second argument of elementWaitingToBeDisplayed.waitForDisplayed to true it waits for the opposite.

Mridul
  • 258
  • 3
  • 9