diff --git a/javascript/node/selenium-webdriver/lib/webdriver.js b/javascript/node/selenium-webdriver/lib/webdriver.js index 364c05c45c899..2943492bd1556 100644 --- a/javascript/node/selenium-webdriver/lib/webdriver.js +++ b/javascript/node/selenium-webdriver/lib/webdriver.js @@ -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) @@ -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( @@ -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) { @@ -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) ) @@ -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) } /** diff --git a/javascript/node/selenium-webdriver/test/lib/form_submit_test.js b/javascript/node/selenium-webdriver/test/lib/form_submit_test.js new file mode 100644 index 0000000000000..68e60798ea794 --- /dev/null +++ b/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'] })