From: RBRi <rb...@us...> - 2018-06-29 14:20:05
|
- **status**: open --> closed --- ** [bugs:#1964] NPE HtmlTextArea.removeFocus()** **Status:** closed **Group:** Latest SVN **Labels:** textarea NPE **Created:** Fri Jun 01, 2018 08:35 AM UTC by Flake **Last Updated:** Fri Jun 29, 2018 02:19 PM UTC **Owner:** RBRi Hi Ron, I encountered a NPE that I didn't expect (haha). (2.32-SNAPSHOT) Assume you have a textarea t. You type something in and then you need to blur it in order for some js to trigger. ~~~java WebClient webClient = new WebClient(BrowserVersion.CHROME); HtmlPage page = webClient.getPage("http://localhost:8080"); HtmlTextArea ta = HtmlPageTools.getHtmlElementById("ta", page); ta.type("test"); ta.removeFocus(); webClient.close(); ~~~ This is how I did it. I used the `removeFocus()` public API beause I didn't know there was `blur()` for textarea, too. However, by doing this you get a NPE because `valueAtFocus_` ain't seem to be set (because you didn't manually `focus()` it). I assumed it was focused after typing something in and it probably is but not via textarea's `focus()`. Actually, after taking a quick look im not sure if it's even focused. The problematic line is this: https://sourceforge.net/p/htmlunit/code/HEAD/tree/trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java#l515 The fix should be as easy as this: ~~~java public void removeFocus() { super.removeFocus(); if (valueAtFocus_ != null && !valueAtFocus_.equals(getText())) { HtmlInput.executeOnChangeHandlerIfAppropriate(this); } valueAtFocus_ = null; } ~~~ Best, Ron2 --- Sent from sourceforge.net because htm...@li... is subscribed to https://sourceforge.net/p/htmlunit/bugs/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/htmlunit/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |