Skip to content

Commit

Permalink
[js] Add support for form submit in W3C mode (fixes #9916) (#9936)
Browse files Browse the repository at this point in the history
* [js] Fixes #9916

* [js] Add support for form submit in W3C mode
  • Loading branch information
harsha509 committed Oct 20, 2021
1 parent 4ac2b4a commit 61dd966
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
15 changes: 9 additions & 6 deletions javascript/node/selenium-webdriver/lib/webdriver.js
Expand Up @@ -2167,7 +2167,7 @@ class TargetLocator {
* @return {!WebElementPromise} The active element.
*/
activeElement() {
var id = this.driver_.execute(
const id = this.driver_.execute(
new command.Command(command.Name.GET_ACTIVE_ELEMENT)
)
return new WebElementPromise(this.driver_, id)
Expand Down Expand Up @@ -2259,7 +2259,7 @@ class TargetLocator {
* when the driver has changed focus to the new window.
*/
newWindow(typeHint) {
var driver = this.driver_
const driver = this.driver_
return this.driver_
.execute(
new command.Command(command.Name.SWITCH_TO_NEW_WINDOW).setParameter(
Expand All @@ -2281,10 +2281,10 @@ class TargetLocator {
* @return {!AlertPromise} The open alert.
*/
alert() {
var text = this.driver_.execute(
const text = this.driver_.execute(
new command.Command(command.Name.GET_ALERT_TEXT)
)
var driver = this.driver_
const driver = this.driver_
return new AlertPromise(
driver,
text.then(function (text) {
Expand Down Expand Up @@ -2614,7 +2614,7 @@ class WebElement {
* requested CSS value.
*/
getCssValue(cssStyleProperty) {
var name = command.Name.GET_ELEMENT_VALUE_OF_CSS_PROPERTY
const name = command.Name.GET_ELEMENT_VALUE_OF_CSS_PROPERTY
return this.execute_(
new command.Command(name).setParameter('propertyName', cssStyleProperty)
)
Expand Down Expand Up @@ -2758,7 +2758,10 @@ class WebElement {
* when the form has been submitted.
*/
submit() {
return this.execute_(new command.Command(command.Name.SUBMIT_ELEMENT))
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)
}

/**
Expand Down
45 changes: 45 additions & 0 deletions javascript/node/selenium-webdriver/test/lib/form_submit_test.js
@@ -0,0 +1,45 @@

// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

'use strict'

const assert = require('assert')
const test = require('../../lib/test')
const until = require('../../lib/until')
const Pages = test.Pages

test.suite(function (env) {
let driver

before(async function () {
driver = await env.builder().build()
})

after(async function () {
return await driver.quit()
})

it('should be able to submit form in W3c mode', async function () {
await driver.get(Pages.formPage);
const form = await driver.findElement({id: 'submitButton'})
await form.submit();
await driver.wait(until.titleIs('We Arrive Here'), 2500)
const success = driver.findElement({id: 'greeting'})
assert.deepStrictEqual(await success.getText(), 'Success!');
})
}, { browsers: ['chrome', 'firefox'] })

0 comments on commit 61dd966

Please sign in to comment.