如何使用player从以下输入中清除值(或将其变为null((使其为空,而不是选中(?
<input
type="radio"
id="yes-in-hand"
value={true}
/>
发件人https://github.com/microsoft/playwright/issues/4924我试过做一些类似的事情:
await this.page.$eval('input[id="yes-in-hand"]', el => el.removeAttribute('value'));
从https://playwright.dev/docs/api/class-locator#locator-填充:
await this.page.locator('input[id="yes-in-hand"]').fill(null); // or undefined - it throws an error: expect a string in .fill function
我还尝试使用https://playwright.dev/docs/api/class-locator#locator-取消选中为:
await this.page.locator('input[id="yes-in-hand"]').uncheck();
// It throws an error: locator.uncheck: Clicking the checkbox did not change its state
但它不起作用,应该有一个适当的方法来做到这一点,只需阅读https://playwright.dev/docs/我找不到。
谢谢。
据我所知,您希望在您的Playwright项目中更改属性的值。
一个很好的参考是以下问题,其中用例删除了一个属性:https://github.com/microsoft/playwright/issues/4924
如果我们应用相同的逻辑,我们可以使用Element.setAttribute(name,value(将inputs属性设置为false。https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
所以这个例子应该是这样的:
const elementHandle = await page.locator(#yes-in-hand);
await elementHandle.evaluate(node => node.setAttribute('value', false));
const elementHandle = await page.locator(#yes-in-hand);
await elementHandle.evaluate(node => node.value = "false");