File tree Expand file tree Collapse file tree
src/org/openqa/selenium/remote Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121import org .openqa .selenium .Beta ;
2222import org .openqa .selenium .By ;
2323import org .openqa .selenium .Dimension ;
24+ import org .openqa .selenium .JavascriptException ;
2425import org .openqa .selenium .OutputType ;
2526import org .openqa .selenium .Point ;
2627import org .openqa .selenium .Rectangle ;
@@ -79,7 +80,12 @@ public void click() {
7980
8081 @ Override
8182 public void submit () {
82- execute (DriverCommand .SUBMIT_ELEMENT (id ));
83+ try {
84+ execute (DriverCommand .SUBMIT_ELEMENT (id ));
85+ } catch (JavascriptException ex ) {
86+ String message = "To submit an element, it must be nested inside a form element" ;
87+ throw new UnsupportedOperationException (message );
88+ }
8389 }
8490
8591 @ Override
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ public void testShouldSubmitAFormWhenAnyElementWithinThatFormIsSubmitted() {
8383 public void testShouldNotBeAbleToSubmitAFormThatDoesNotExist () {
8484 driver .get (pages .formPage );
8585 WebElement element = driver .findElement (By .name ("SearchableText" ));
86- assertThatExceptionOfType (JavascriptException .class ).isThrownBy (element ::submit );
86+ assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (element ::submit );
8787 }
8888
8989 @ Test
@@ -282,14 +282,10 @@ public void testCanClickOnAnExternalImplicitSubmitButton() {
282282
283283 @ Test
284284 public void canSubmitFormWithSubmitButtonIdEqualToSubmit () {
285- String blank = appServer .create (new Page ().withTitle ("Submitted Successfully!" ));
286- driver .get (appServer .create (new Page ().withBody (
287- String .format ("<form action='%s'>" , blank ),
288- " <input type='submit' id='submit' value='Submit'>" ,
289- "</form>" )));
290-
291- driver .findElement (By .id ("submit" )).submit ();
292- wait .until (titleIs ("Submitted Successfully!" ));
285+ driver .get (pages .formPage );
286+ driver .findElement (By .id ("submit" )).click ();
287+ wait .until (titleIs ("We Arrive Here" ));
288+ assertThat (driver .getTitle ()).isEqualTo ("We Arrive Here" );
293289 }
294290
295291 @ Test
You can’t perform that action at this time.
0 commit comments