2

This is the input tag that I want to get date value

<input readonly="" name="issued_at" type="text" placeholder=" " id="issued_at" data-testid="issued_at--input" autocomplete="new-textBox" value="5/3/2023">

I need to get the date value in this tag.

I wrote this function for getting the value but it didn't worked for me

async daysBetweenDates() {
    const issueDateBox = await this.page.$('input#issued_at');
    const issueDateText = await issueDateBox.getAttribute('value');
    console.log(issueDateText);
}

I got this error:

TypeError: Cannot read properties of null (reading 'getAttribute')

Any idea?

Thanks in advance!

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

1 Answers1

1

How to get input value in playwright?

Use Locator inputValue to get input value.

const value = await this.page.locator('input#').inputValue();

And the text value can be verified with toHaveValue :

const locator = page.locator('input#');
await expect(locator).toHaveValue('SomeText'); 

Reference:https://playwright.dev/docs/api/class-locator#locator-input-value

Getting value of input element in Playwright

Vishal Aggarwal
  • 1,929
  • 1
  • 13
  • 23