question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Keys` is not defined when using `keyDown` action

See original GitHub issue

When trying to create a test which checks the result of an option + click() event in my app, Keys is not defined.

This is the test being run (apologies if the JS looks malformed, it’s converted from CoffeeScript):

var driver = new webdriver.Builder()
    .usingServer('http://localhost:4444/wd/hub')
    .withCapabilities(webdriver.Capabilities.chrome()).build()

driver.manage().timeouts().setScriptTimeout(30000)
var ptor = protractor.wrapDriver(driver)

it('opens new tab with OPTION+click', function() {
    ptor.keyDown(Keys.ALT)
        .then(function() {
            ptor.findElement(protractor.By.repeater('item in ses.items').row(4).column("{{item.subject}}")).click();
            ptor.keyUp(Keys.ALT);
        })

    ptor.findElements(protractor.By.repeater('item in ses.navItems'));
        .then(function(tabs) {
            expect(tabs.length).toBe(1);
        });
});

I’ve also tried the following variations for Keys.ALT: ptor.driver.Keys.ALT, ptor.driver.Key.ALT, and Key.ALT

It’s entirely possible I’m not writing this test correctly. If that’s the case I’d appreciate any pointers in testing clicks with key modifiers.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:19 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Douwe92commented, Sep 11, 2013

Maybe I am not getting it… I am trying to get one Enter click but it just doesn’t working.

I also get Keys is not defined. What is the good way of getting one enter click?

0reactions
Basman01commented, Dec 19, 2013

Thank you all for your help i now got it working

i made a little change and i now got it working with this :

var search = element(by.id(‘possearch_00A’)); search.sendKeys(‘+tegoedbon’,protractor.Key.ENTER);

because it can now use sendKeys you can just send the ENTER aswell 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Game KeyDown event & keyboard actions not ...
//player (keyboard) input var keysDown= {}; document.addEventListener("keyDown", function(e) { console.log('key press'); keysDown[e. ... keyCode] ...
Read more >
Element: keydown event - Web APIs | MDN
The keydown event is fired when a key is pressed. Unlike the deprecated keypress event, the keydown event is fired for all keys, ......
Read more >
Keyboard: keydown and keyup
Pressing a key always generates a keyboard event, be it symbol keys or special keys like Shift or Ctrl and so on. The...
Read more >
Control.KeyDown Event (System.Windows.Forms)
KeyCode != Keys.Back) { // A non-numerical keystroke was pressed. // Set the flag to true and evaluate in KeyPress event. nonNumberEntered =...
Read more >
.keydown() | jQuery API Documentation
To determine which key was pressed, examine the event object that is passed to the handler function. While browsers use differing properties to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found