HtmlUnit / htmlunit

HtmlUnit is a "GUI-Less browser for Java programs".
https://www.htmlunit.org
Apache License 2.0
875 stars 172 forks source link

page.getFocusedElement() returns null in page with element with autofocus #607

Open corlaez opened 1 year ago

corlaez commented 1 year ago

My page has an input with autofocus="autofocus" but page.getFocusedElement() is null. I can confirm the page has the contents I expect. Moreover the input has the autofocus in page.asXML()

<input name="content" class="new-todo" placeholder="What needs to be done?" hx-vals="{&quot;completed&quot;:&quot;off&quot;}" hx-post="/todo?" hx-target="body" hx-trigger="keyup[key=='Enter']" hx-on="htmx:beforeRequest: event.target.readOnly = true" required="required" autofocus="autofocus"/>

I expected to see get my input in page.getFocusedElement(). Is this not implemented or did I miss something? Should it be a bug?

page.asXML(): ```XML Ktor + htmx

todos

Double-click to edit a todo

Created by Armando Cordova

Inpired by TodoMVC

```
HTML String returned by my browser: ```Handlebars Ktor + htmx

todos

```
rbri commented 1 year ago

Will have a look after my vacation...

corlaez commented 1 year ago

Sure thing, in the meantime I am using "//*[@autofocus='autofocus']" to retrieve the autofocused element.