File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed
src/org/openqa/selenium/remote Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change 21
21
import org .openqa .selenium .Beta ;
22
22
import org .openqa .selenium .By ;
23
23
import org .openqa .selenium .Dimension ;
24
+ import org .openqa .selenium .JavascriptException ;
24
25
import org .openqa .selenium .OutputType ;
25
26
import org .openqa .selenium .Point ;
26
27
import org .openqa .selenium .Rectangle ;
@@ -79,7 +80,12 @@ public void click() {
79
80
80
81
@ Override
81
82
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
+ }
83
89
}
84
90
85
91
@ Override
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ public void testShouldSubmitAFormWhenAnyElementWithinThatFormIsSubmitted() {
83
83
public void testShouldNotBeAbleToSubmitAFormThatDoesNotExist () {
84
84
driver .get (pages .formPage );
85
85
WebElement element = driver .findElement (By .name ("SearchableText" ));
86
- assertThatExceptionOfType (JavascriptException .class ).isThrownBy (element ::submit );
86
+ assertThatExceptionOfType (UnsupportedOperationException .class ).isThrownBy (element ::submit );
87
87
}
88
88
89
89
@ Test
@@ -282,14 +282,10 @@ public void testCanClickOnAnExternalImplicitSubmitButton() {
282
282
283
283
@ Test
284
284
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" );
293
289
}
294
290
295
291
@ Test
You can’t perform that action at this time.
0 commit comments