问题
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