I'm automating a test using Selenium (Node.js) and trying to set a value for a datetime-local input. The UI visually shows the correct date/time, but when I inspect the element after driver.sleep(), the input has no value attribute at all.
If I manually pick a date using the browser picker, then the value attribute appears.
So Selenium is updating the UI, but the actual React state is not being updated.
React code:
<div>
<label className="text-sm text-gray-600" htmlFor="start_time">
Start Time
</label>
<input
type="datetime-local"
id="start_time"
value={form.start_time}
onChange={(e) => setForm({ ...form, start_time: e.target.value })}
className="w-full border rounded px-3 py-2"
/>
</div>
Selenium code:
const startInput = await driver.findElement(
By.xpath(
"//label[contains(text(), 'Start Time')]/following-sibling::input[@type='datetime-local']"
)
);
await driver.executeScript(
"arguments[0].value = arguments[1]; arguments[0].dispatchEvent(new Event('input', { bubbles: true })); arguments[0].dispatchEvent(new Event('change', { bubbles: true }));",
startInput,
"2025-11-19T13:45"
);
Why is Selenium able to visually change the value, but React does not register the change?