Home > Enterprise >  Cannot figure out how to wait for text in input value
Cannot figure out how to wait for text in input value

Time:03-28

Scenario: I need to wait for some specific text to load on the page, the issue im experiencing is that the text is the value of an input box and this value is the last thing on the page to load/appear.

I was wondering if there was some way to tell playwright:

wait for the text value in this input box to = "text input value"

I've used await this.page.locator('my locator').inputValue(); but I noticed that the value can sometimes return blank when the page takes a little longer to load so i need to specifically wait for it before continuing.

at the moment Im waiting for a specific Api request to complete which works for now, but I was wondering if there was a better way?

Any help would be appreciated.

CodePudding user response:

How about you use the locator assertions to have value with custom timeout. Something like:

const locator = page.locator('my locator')
await expect(locator).toHaveValue('your value', {timeout: 20000})

CodePudding user response:

Try this:

await page.waitForSelector('text=Log in',{timeout:25000})

adapt the selector, you can use text or css or xpath. And you can change timeout value to one that suits you, it is in mili seconds.

  • Related