protractor icon indicating copy to clipboard operation
protractor copied to clipboard

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

Open stickel opened this issue 13 years ago • 19 comments

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.

stickel avatar Aug 20 '13 20:08 stickel

Root cause of this is #46

selenium-webdriver's Keys is exported onto webdriver, not onto an instance of webdriver. So ptor.webdriver.Keys won't work.

juliemr avatar Aug 22 '13 22:08 juliemr

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?

Douwe92 avatar Sep 11 '13 07:09 Douwe92

If you're using ptor = protractor.getInstance() here's an example of performing a keyboard action:

    ptor.actions()
        .keyPress(ptor.Key.ENTER)
        .perform()

You could have whatever you want before or after this example.

Here's an example from an app I'm working on which OPT+clicks a link:

ptor.findElement(protractor.By.repeater('caseObj in ses.cases').row(2).column("{{caseObj.subjectDisplay}}"))
  .then (el) ->
    ptor.actions()
      .keyDown(protractor.Key.ALT)
      .click(el)
      .keyUp(protractor.Key.ALT)
      .perform()
ptor.findElements(protractor.By.css('.header .case-tabs .case-tab'))
  .then (tabs) ->
    expect(tabs.length).toBe 2

stickel avatar Sep 11 '13 15:09 stickel

Ahh thanks, I misunderstood it!

Douwe92 avatar Sep 12 '13 07:09 Douwe92

ptor.actions().dragAndDrop(el1, el2).perform(); when i perform this, it seems only mouseDown() happens without any mouseMove() and mouseUp() taking effect. i am quite sure el1 and el2 are web elements. ?

elaijuh avatar Sep 19 '13 17:09 elaijuh

TypeError: Cannot read property 'ENTER' of undefined

when using ptor.actions().keyPress(ptor.Key.ENTER).perform();

Douwe92 avatar Sep 24 '13 08:09 Douwe92

@Douwe92 Is angular available on the page performing the actions? Try ptor.actions().keyPress(protractor.Key.ENTER).perform() (protractor.Key instead of ptor.Key)

stickel avatar Sep 24 '13 18:09 stickel

@mopodo If you're still having an issue with dragAndDrop, could you comment on #123 with what you're experiencing.

stickel avatar Sep 30 '13 22:09 stickel

Hello.

I have a problen when I try to move and element in my workspace. I want simulate a action sequence: 1- Mouse down when selecting an element with the left mouse click 2- Mouse move at a certain page position (dragging). 3- Mouse up.

I've implemented this code but my element doesn't move.

browser.actions().
mouseDown(element,protractor.Button.LEFT). mouseMove({x:100, y:100}). mouseUp(element,protractor.Button.LEFT). perform()

Any idea??

Thank you very much

frankPairs avatar Dec 12 '13 11:12 frankPairs

i have this in my code :

ptor.actions().keyPress(protractor.Key.RETURN).perform()

and it gives me this error :

TypeError: Object [object Object] has no method 'keyPress'

Any ideas for fix??

Basman01 avatar Dec 16 '13 15:12 Basman01

I think you have to implement:

ptor.actions().keyDown(protractor.key.RETURN).perform()

I've used keyDown method and works correctly.

frankPairs avatar Dec 16 '13 15:12 frankPairs

i have tried that and now it gives me :

Error: Not a modifier key

Basman01 avatar Dec 16 '13 15:12 Basman01

I show you how I've done a combo keys (control+A):

browser.actions().keyDown(protractor.Key.CONTROL).sendKeys('a').perform()

frankPairs avatar Dec 16 '13 16:12 frankPairs

Change protractor.Key.RETURN to protractor.Key.ENTER I don't think "return" is the correct key name.

On Mon, Dec 16, 2013 at 8:31 AM, Francisco Parejo [email protected] wrote:

I show you how I've done a combo keys (control+A):

browser.actions().keyDown(protractor.Key.CONTROL).sendKeys('a').perform()

Reply to this email directly or view it on GitHub: https://github.com/angular/protractor/issues/48#issuecomment-30675171

stickel avatar Dec 16 '13 18:12 stickel

i have tried ENTER instead of RETURN now this is my code :

ptor.actions().keyDown(protractor.Key.ENTER).perform()

and it gives me :

Error: Not a modifier key

Basman01 avatar Dec 17 '13 07:12 Basman01

What are you trying to hit the enter key on? What code is around ptor.actions()?

stickel avatar Dec 17 '13 20:12 stickel

let me discribe my situation for you :

i am writing a test to check everything on the page is working ,but i have a search bar in the header and the header is set there by the code ${pageheader} so the header itself is not in the .html file i gets loaded in

and when i try ptor.findElement(protractor.By.id('search')).sendKeys('001095000020' , protractor.Key.RETURN); (For your information RETURN works in the other fields) it says that the element is not visible

what i am trying now is : browser.executeScript('document.getElementById("search").value = "001095000020";');

with this code it fills the search field i now only need it to press enter (because i also cant aprroach the button next to it)

so the code around ptor.actions() is :

browser.executeScript('document.getElementById("possearch_00A").value = "001095000020";'); ptor.sleep(2000); ptor.actions().keyDown(protractor.Key.ENTER).perform(); ptor.sleep(2000);

Basman01 avatar Dec 18 '13 09:12 Basman01

Why are you executing a script to set the value of the element? Try something like this:

var search = element(by.id('search'));
search.sendKeys('00109500000020');
browser.actions().keyPress(protractor.Key.ENTER).perform();

juliemr avatar Dec 18 '13 19:12 juliemr

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 :)

Basman01 avatar Dec 19 '13 08:12 Basman01