`Keys` is not defined when using `keyDown` action
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.
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.
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?
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
Ahh thanks, I misunderstood it!
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. ?
TypeError: Cannot read property 'ENTER' of undefined
when using ptor.actions().keyPress(ptor.Key.ENTER).perform();
@Douwe92 Is angular available on the page performing the actions? Try ptor.actions().keyPress(protractor.Key.ENTER).perform() (protractor.Key instead of ptor.Key)
@mopodo If you're still having an issue with dragAndDrop, could you comment on #123 with what you're experiencing.
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
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??
I think you have to implement:
ptor.actions().keyDown(protractor.key.RETURN).perform()
I've used keyDown method and works correctly.
i have tried that and now it gives me :
Error: Not a modifier key
I show you how I've done a combo keys (control+A):
browser.actions().keyDown(protractor.Key.CONTROL).sendKeys('a').perform()
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
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
What are you trying to hit the enter key on? What code is around ptor.actions()?
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);
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();
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 :)