[HtmlUnit] [htmlunit:feature-requests] #258 HtmlButtonInput parsed as an HtmlTextInput
RBRi via HtmlUnit-develop <[email protected]> Fri, 25 Jan 2019 19:26:14 -0000
| Newsgroups | gmane.comp.java.htmlunit.devel |
|---|---|
| Message-ID | </p/htmlunit/feature-requests/258/097577d685341e528ef21efd2943706f07827b22.feature-requests@htmlunit.p.sourceforge.net> |
- **status**: pending --> closed
- **Comment**:
thenks for the feedback, enjoy HtmlUnit
---
** [feature-requests:#258] HtmlButtonInput parsed as an HtmlTextInput**
**Status:** closed
**Group:** Latest SVN
**Created:** Thu Jan 24, 2019 02:56 PM UTC by Ryan Holt
**Last Updated:** Fri Jan 25, 2019 02:52 PM UTC
**Owner:** RBRi
**Attachments:**
- [HtmlButtonInputTest.java](https://sourceforge.net/p/htmlunit/feature-requests/258/attachment/HtmlButtonInputTest.java) (2.9 kB; application/octet-stream)
Our project requires us to interact with server-generated HTML that is often malformed or has invalid content that browsers will handle but HtmlUnit will trip over.
For example, I am unable to get all the attributes of this input element because the parser appears to short-circuit when it reaches the superfluous `=''=""` characters.
`<input name='button' id='button' =''="" value="Do you even HTML?" onClick='alert("foo")' type='button' >`
HtmlUnit parses this object as an HtmlTextInput instead of a HtmlButtonInput, and the 'value' and 'onClick' attributes are missing from the object's attributes map.
It would be incredibly valuable for us to be able to parse web pages with malformed HTML because 1.) we don't have control over the serves that generae this content and 2.) these systems are not going away any time soon.
I'm willing to help where I can. I've started by creating a simple unit test that will reproduce this issue.
```
/**
* @throws Exception if the test fails
*/
@Test
@Alerts("foo")
public void click_onClick_badFormat() throws Exception {
final String htmlContent
= "<html><head><title>foo</title></head><body>\n"
+ "<form id='form1' onSubmit='alert(\"bar\")'>\n"
+ " <input name='button' id='button' "
+ "=''=\"\" value=\"Do you even HTML?\""
+ "onClick='alert(\"foo\")' type='button' >\n"
+ "</form></body></html>";
final List<String> collectedAlerts = new ArrayList<>();
final HtmlPage page = loadPage(htmlContent, collectedAlerts);
final HtmlButtonInput button = page.getHtmlElementById("button");
final HtmlPage secondPage = button.click();
assertEquals(getExpectedAlerts(), collectedAlerts);
assertSame(page, secondPage);
}
```
Results in:
```
java.lang.ClassCastException: com.gargoylesoftware.htmlunit.html.HtmlTextInput cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlButtonInput
at com.gargoylesoftware.htmlunit.html.HtmlButtonInputTest.click_onClick_badFormat(HtmlButtonInputTest.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at com.gargoylesoftware.htmlunit.ErrorOutputChecker$1.evaluate(ErrorOutputChecker.java:78)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at com.gargoylesoftware.htmlunit.runners.BrowserStatement.evaluateSolo(BrowserStatement.java:139)
at com.gargoylesoftware.htmlunit.runners.BrowserStatement.evaluate(BrowserStatement.java:56)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
```
---
Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/htmlunit/feature-requests/
To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/htmlunit/admin/feature-requests/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.
_______________________________________________
HtmlUnit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop