Skip to content

Commit d1729da

Browse files
committed
reflect selenium change
1 parent 23b49bc commit d1729da

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/main/java/org/openqa/selenium/htmlunit/HtmlUnitWebElement.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.openqa.selenium.Dimension;
5555
import org.openqa.selenium.ElementNotInteractableException;
5656
import org.openqa.selenium.InvalidElementStateException;
57-
import org.openqa.selenium.JavascriptException;
5857
import org.openqa.selenium.OutputType;
5958
import org.openqa.selenium.Point;
6059
import 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
}

src/test/java/org/openqa/selenium/htmlunit/html/HtmlPage3Test.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.junit.Test;
2121
import org.junit.runner.RunWith;
22+
import org.openqa.selenium.By;
2223
import org.openqa.selenium.WebDriver;
2324
import org.openqa.selenium.htmlunit.WebDriverTestCase;
2425
import 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
}

0 commit comments

Comments
 (0)