I have a disabled input field, and I want to enable it using Playwright.
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" disabled>
<input type="submit" value="Submit">
</form>
I want to check if a low permission level user enables it through dev-tools, the submit form would block/fail.
1
I’ve found a solution using the evaluate
Playwright method.
The page.evaluate() API allows you to run JavaScript code in the context of the web page.
In this case I’m using it to remove the disabled
attribute of the input field:
const inputSelector = "#fname";
await page.evaluate((selector) => {
const inputElement = document.querySelector(selector);
if (inputElement) {
inputElement.removeAttribute("disabled");
}
}, inputSelector);
Now the input field would be enabled.