Skip to content

Commit 7c77d06

Browse files
committed
[js] update implementation for submitting forms
1 parent bcc7618 commit 7c77d06

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

javascript/node/selenium-webdriver/lib/webdriver.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2765,13 +2765,17 @@ class WebElement {
27652765
* when the form has been submitted.
27662766
*/
27672767
submit() {
2768-
const form = this.findElement({ xpath: './ancestor-or-self::form' })
2769-
this.driver_.executeScript(
2770-
"var e = arguments[0].ownerDocument.createEvent('Event');" +
2771-
"e.initEvent('submit', true, true);" +
2772-
'if (arguments[0].dispatchEvent(e)) { arguments[0].submit() }',
2773-
form
2774-
)
2768+
const script = "var form = arguments[0];\n" +
2769+
"while (form.nodeName != \"FORM\" && form.parentNode) {\n" +
2770+
" form = form.parentNode;\n" +
2771+
"}\n" +
2772+
"if (!form) { throw Error('Unable to find containing form element'); }\n" +
2773+
"if (!form.ownerDocument) { throw Error('Unable to find owning document'); }\n" +
2774+
"var e = form.ownerDocument.createEvent('Event');\n" +
2775+
"e.initEvent('submit', true, true);\n" +
2776+
"if (form.dispatchEvent(e)) { HTMLFormElement.prototype.submit.call(form) }\n";
2777+
2778+
this.driver_.executeScript(script, this);
27752779
}
27762780

27772781
/**

0 commit comments

Comments
 (0)