Protractor version 5.2.0 - How to pass a specific key (Ex: TAB) as a parameter in sendkeys()?

﹥>﹥吖頭↗ 提交于 2020-01-24 00:18:12

问题


I wanted to pass the key names as a parameter, to make it more reusable instead of hard coding.

Just something like below

function Keyboardaction(keys)
    {
    return browser.actions().sendKeys(protractor.Key.(keys)).perform();
    }

Keyboardaction(TAB);

Can anyone help on the same


回答1:


You can do this

function Keyboardaction(keys)
{
    return browser.actions().sendKeys(protractor.Key[keys]).perform();
}

Keyboardaction("TAB");

but then you'll want to pass multiple keys, or chords, send it to particular element etc and this won't work for you. And all because the approach is fundamentally incorrect. But if it works for you, go for it



来源:https://stackoverflow.com/questions/58626150/protractor-version-5-2-0-how-to-pass-a-specific-key-ex-tab-as-a-parameter-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!