How do I return the value of elem so that I can verify that it is in fact 1
?
const elem = await page.$('input#my-input')
await elem.fill('1')
inputValue
method has been added in Playwright v1.13.0
await page.inputValue('input#my-input');
It returns input.value
for the selected <input>
or <textarea>
element. Throws for non-input elements. Read more.
The easiest way is to use $eval
. Here you see a small example:
const playwright = require("playwright");
(async () => {
const browser = await playwright.chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.setContent(`<input id="foo"/>`);
await page.type("#foo", "New value")
console.log(await page.$eval("#foo", el => el.value))
await page.screenshot({ path: `example.png` });
await browser.close();
})();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With