Skip to content

Commit 61dd966

Browse files
authored
[js] Add support for form submit in W3C mode (fixes #9916) (#9936)
* [js] Fixes #9916 * [js] Add support for form submit in W3C mode
1 parent 4ac2b4a commit 61dd966

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,7 +2167,7 @@ class TargetLocator {
21672167
* @return {!WebElementPromise} The active element.
21682168
*/
21692169
activeElement() {
2170-
var id = this.driver_.execute(
2170+
const id = this.driver_.execute(
21712171
new command.Command(command.Name.GET_ACTIVE_ELEMENT)
21722172
)
21732173
return new WebElementPromise(this.driver_, id)
@@ -2259,7 +2259,7 @@ class TargetLocator {
22592259
* when the driver has changed focus to the new window.
22602260
*/
22612261
newWindow(typeHint) {
2262-
var driver = this.driver_
2262+
const driver = this.driver_
22632263
return this.driver_
22642264
.execute(
22652265
new command.Command(command.Name.SWITCH_TO_NEW_WINDOW).setParameter(
@@ -2281,10 +2281,10 @@ class TargetLocator {
22812281
* @return {!AlertPromise} The open alert.
22822282
*/
22832283
alert() {
2284-
var text = this.driver_.execute(
2284+
const text = this.driver_.execute(
22852285
new command.Command(command.Name.GET_ALERT_TEXT)
22862286
)
2287-
var driver = this.driver_
2287+
const driver = this.driver_
22882288
return new AlertPromise(
22892289
driver,
22902290
text.then(function (text) {
@@ -2614,7 +2614,7 @@ class WebElement {
26142614
* requested CSS value.
26152615
*/
26162616
getCssValue(cssStyleProperty) {
2617-
var name = command.Name.GET_ELEMENT_VALUE_OF_CSS_PROPERTY
2617+
const name = command.Name.GET_ELEMENT_VALUE_OF_CSS_PROPERTY
26182618
return this.execute_(
26192619
new command.Command(name).setParameter('propertyName', cssStyleProperty)
26202620
)
@@ -2758,7 +2758,10 @@ class WebElement {
27582758
* when the form has been submitted.
27592759
*/
27602760
submit() {
2761-
return this.execute_(new command.Command(command.Name.SUBMIT_ELEMENT))
2761+
const form = this.findElement({xpath:"./ancestor-or-self::form"});
2762+
this.driver_.executeScript("var e = arguments[0].ownerDocument.createEvent('Event');"+
2763+
"e.initEvent('submit', true, true);"+
2764+
"if (arguments[0].dispatchEvent(e)) { arguments[0].submit() }", form)
27622765
}
27632766

27642767
/**
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
19+
'use strict'
20+
21+
const assert = require('assert')
22+
const test = require('../../lib/test')
23+
const until = require('../../lib/until')
24+
const Pages = test.Pages
25+
26+
test.suite(function (env) {
27+
let driver
28+
29+
before(async function () {
30+
driver = await env.builder().build()
31+
})
32+
33+
after(async function () {
34+
return await driver.quit()
35+
})
36+
37+
it('should be able to submit form in W3c mode', async function () {
38+
await driver.get(Pages.formPage);
39+
const form = await driver.findElement({id: 'submitButton'})
40+
await form.submit();
41+
await driver.wait(until.titleIs('We Arrive Here'), 2500)
42+
const success = driver.findElement({id: 'greeting'})
43+
assert.deepStrictEqual(await success.getText(), 'Success!');
44+
})
45+
}, { browsers: ['chrome', 'firefox'] })

0 commit comments

Comments
 (0)