File tree Expand file tree Collapse file tree
main/java/org/openqa/selenium/htmlunit
test/java/org/openqa/selenium/htmlunit/html Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5454import org .openqa .selenium .Dimension ;
5555import org .openqa .selenium .ElementNotInteractableException ;
5656import org .openqa .selenium .InvalidElementStateException ;
57- import org .openqa .selenium .JavascriptException ;
5857import org .openqa .selenium .OutputType ;
5958import org .openqa .selenium .Point ;
6059import org .openqa .selenium .Rectangle ;
@@ -123,14 +122,16 @@ else if ((element_ instanceof HtmlSubmitInput) || (element_ instanceof HtmlImage
123122 else if (element_ instanceof HtmlInput ) {
124123 final HtmlForm form = ((HtmlElement ) element_ ).getEnclosingForm ();
125124 if (form == null ) {
126- throw new JavascriptException ("Unable to find the containing form" );
125+ throw new UnsupportedOperationException (
126+ "To submit an element, it must be nested inside a form element" );
127127 }
128128 submitForm (form );
129129 }
130130 else {
131131 final HtmlUnitWebElement form = findParentForm ();
132132 if (form == null ) {
133- throw new JavascriptException ("Unable to find the containing form" );
133+ throw new UnsupportedOperationException (
134+ "To submit an element, it must be nested inside a form element" );
134135 }
135136 form .submitImpl ();
136137 }
Original file line number Diff line number Diff line change 1919
2020import org .junit .Test ;
2121import org .junit .runner .RunWith ;
22+ import org .openqa .selenium .By ;
2223import org .openqa .selenium .WebDriver ;
2324import org .openqa .selenium .htmlunit .WebDriverTestCase ;
2425import org .openqa .selenium .htmlunit .junit .BrowserRunner ;
@@ -46,4 +47,22 @@ public void constructor() throws Exception {
4647 final WebDriver driver = loadPage2 (html );
4748 assertEquals ("foo" , driver .getTitle ());
4849 }
50+
51+ /**
52+ * @throws Exception if the test fails
53+ */
54+ @ Test (expected = UnsupportedOperationException .class )
55+ public void submitWithoutForm () throws Exception {
56+ final String html =
57+ "<html>\n "
58+ + "<body>\n "
59+ + " <input id='t' type='text' value='abcd'>\n "
60+ + "</body>\n "
61+ + "</html>" ;
62+
63+ final WebDriver driver = loadPage2 (html );
64+ driver .findElement (By .id ("t" )).submit ();
65+
66+ assertEquals (1 , getMockWebConnection ().getRequestCount ());
67+ }
4968}
You can’t perform that action at this time.
0 commit comments