Skip to content

Commit 67d544b

Browse files
committed
[JS] Add support for Actions API sendKeys to designated element
1 parent 9b012df commit 67d544b

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,13 @@ class Actions {
801801
* @return {!Actions} a self reference.
802802
*/
803803
sendKeys(...keys) {
804+
const { WebElement } = require('./webdriver')
805+
804806
const actions = []
807+
if(keys.length > 1 && keys[0] instanceof WebElement) {
808+
this.click(keys[0]);
809+
keys.shift()
810+
}
805811
for (const key of keys) {
806812
if (typeof key === 'string') {
807813
for (const symbol of key) {

javascript/node/selenium-webdriver/test/actions_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,21 @@ suite(function (env) {
239239
assert.strictEqual(await el.getAttribute('value'), 'foobar')
240240
})
241241

242+
it('can send keys to designated element', async function () {
243+
await driver.get(Pages.formPage)
244+
245+
let el = await driver.findElement(By.id('email'))
246+
assert.strictEqual(await el.getAttribute('value'), '')
247+
248+
await driver.actions().sendKeys(el, 'foobar').perform()
249+
250+
await driver.wait(
251+
async () => (await el.getAttribute('value')) === 'foobar',
252+
10000
253+
)
254+
assert.strictEqual(await el.getAttribute('value'), 'foobar')
255+
})
256+
242257
ignore(env.browsers(Browser.FIREFOX, Browser.SAFARI)).it(
243258
'can scroll with the wheel input',
244259
async function () {

0 commit comments

Comments
 (0)