Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions packages/protocol/tests/browser-runtime/rpc-client-smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,25 @@ describe("Stagehand service worker RPC client smoke", () => {
}),
).resolves.toBe("clicked:user@example.com");

await expect(
activeRpcClient.send(StagehandMethods.locatorFill, {
pageId: page.pageId,
selector: "#locator-date",
value: "2026-07-21",
}),
).resolves.toStrictEqual({ filled: true });
await expect(
activeRpcClient.send(StagehandMethods.locatorInputValue, {
pageId: page.pageId,
selector: "#locator-date",
}),
).resolves.toBe("2026-07-21");
for (const { selector, value } of [
{ selector: "#locator-date", value: "2026-07-21" },
{ selector: "#locator-time", value: "14:30" },
{ selector: "#locator-datetime-local", value: "2026-07-21T09:15" },
] as const) {
await expect(
activeRpcClient.send(StagehandMethods.locatorFill, {
pageId: page.pageId,
selector,
value,
}),
).resolves.toStrictEqual({ filled: true });
await expect(
activeRpcClient.send(StagehandMethods.locatorInputValue, {
pageId: page.pageId,
selector,
}),
).resolves.toBe(value);
}

await expect(
activeRpcClient.send(StagehandMethods.locatorIsVisible, {
Expand Down Expand Up @@ -637,6 +643,8 @@ async function startFixtureServer(): Promise<FixtureServer> {
<input id="locator-input" name="email" />
<label for="locator-date">Date</label>
<input id="locator-date" type="date" />
<input id="locator-time" type="time" />
<input id="locator-datetime-local" type="datetime-local" />
<button
id="locator-button"
onclick="document.querySelector('#locator-output').textContent = 'clicked:' + document.querySelector('#locator-input').value;"
Expand Down
32 changes: 19 additions & 13 deletions packages/sdk-ts/tests/integration/locatorFill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,32 @@ describe("Locator.fill()", () => {
await closeStagehand(stagehand);
});

it("fills date inputs via value setter even when beforeinput blocks insertText", async () => {
const page = await firstPage(stagehand);
await page.goto(
"data:text/html," +
encodeURIComponent(`<!doctype html><html><body>
<input id="date" type="date" />
it.each([
{ type: "date", value: "2026-01-01" },
{ type: "time", value: "14:30" },
{ type: "datetime-local", value: "2026-01-01T14:30" },
] as const)(
"fills $type inputs via value setter even when beforeinput blocks insertText",
async ({ type, value }) => {
const page = await firstPage(stagehand);
await page.goto(
"data:text/html," +
encodeURIComponent(`<!doctype html><html><body>
<input id="target" type="${type}" />
<script>
const input = document.getElementById('date');
const input = document.getElementById('target');
input.addEventListener('beforeinput', (event) => {
if (event && event.inputType === 'insertText') event.preventDefault();
});
</script>
</body></html>`),
);
);

const dateInput = page.locator("xpath=/html/body/input");
await dateInput.fill("2026-01-01");
const value = await dateInput.inputValue();
expect(value).toBe("2026-01-01");
});
const input = page.locator("xpath=/html/body/input");
await input.fill(value);
expect(await input.inputValue()).toBe(value);
},
);

it("xpath case: throws an error when fill encounters an exception", async () => {
const page = await firstPage(stagehand);
Expand Down