From 3c3786e584bcede0bd980bf772cc06f954984f32 Mon Sep 17 00:00:00 2001 From: duonglaiquang Date: Fri, 13 Mar 2026 11:43:35 +0900 Subject: [PATCH] HtmlElement: fix a bug where input event not fired with type=email/url/date/time --- .../java/org/htmlunit/html/HtmlElement.java | 8 ++----- .../org/htmlunit/html/HtmlElementTest.java | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/htmlunit/html/HtmlElement.java b/src/main/java/org/htmlunit/html/HtmlElement.java index cfbe57775b..53e3548e3c 100644 --- a/src/main/java/org/htmlunit/html/HtmlElement.java +++ b/src/main/java/org/htmlunit/html/HtmlElement.java @@ -592,12 +592,8 @@ private Page type(final char c, final boolean lastType) } final WebClient webClient = page.getWebClient(); - if (this instanceof HtmlTextInput - || this instanceof HtmlTextArea - || this instanceof HtmlTelInput - || this instanceof HtmlNumberInput - || this instanceof HtmlSearchInput - || this instanceof HtmlPasswordInput) { + if (this instanceof HtmlSelectableTextInput + || this instanceof HtmlTextArea) { fireEvent(new KeyboardEvent(this, Event.TYPE_INPUT, c, shiftPressed_ || isShiftNeeded, ctrlPressed_, altPressed_)); } diff --git a/src/test/java/org/htmlunit/html/HtmlElementTest.java b/src/test/java/org/htmlunit/html/HtmlElementTest.java index 1e3fd8c37a..abd956b8a2 100644 --- a/src/test/java/org/htmlunit/html/HtmlElementTest.java +++ b/src/test/java/org/htmlunit/html/HtmlElementTest.java @@ -1269,4 +1269,27 @@ public void acceptChar() throws Exception { input.type(value); assertEquals(value, input.getValue()); } + + /** + * @throws Exception if an error occurs + */ + @Test + public void typeFiresInputEvent() throws Exception { + final String[] types = {"text", "tel", "number", "search", "password", "email", "url", "date", "time"}; + + for (final String type : types) { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + "\n" + + ""; + final HtmlPage page = loadPage(html); + page.getHtmlElementById("t").type("ab"); + assertEquals("input event for type=" + type, "inputinput", page.getTitleText()); + } + } }