Skip to content

Commit

Permalink
[js] update implementation for submitting forms
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed May 25, 2022
1 parent bcc7618 commit 7c77d06
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2765,13 +2765,17 @@ class WebElement {
* when the form has been submitted.
*/
submit() {
const form = this.findElement({ xpath: './ancestor-or-self::form' })
this.driver_.executeScript(
"var e = arguments[0].ownerDocument.createEvent('Event');" +
"e.initEvent('submit', true, true);" +
'if (arguments[0].dispatchEvent(e)) { arguments[0].submit() }',
form
)
const script = "var form = arguments[0];\n" +
"while (form.nodeName != \"FORM\" && form.parentNode) {\n" +
" form = form.parentNode;\n" +
"}\n" +
"if (!form) { throw Error('Unable to find containing form element'); }\n" +
"if (!form.ownerDocument) { throw Error('Unable to find owning document'); }\n" +
"var e = form.ownerDocument.createEvent('Event');\n" +
"e.initEvent('submit', true, true);\n" +
"if (form.dispatchEvent(e)) { HTMLFormElement.prototype.submit.call(form) }\n";

this.driver_.executeScript(script, this);
}

/**
Expand Down

0 comments on commit 7c77d06

Please sign in to comment.