Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send Keyboard keys in protractor like TAB

Tags:

protractor

I need to select an element, send values to it, press tab and then send new values.

I can select the element and send values to it but am not being able to send TAB from my keyboard and then send new value.

I used ptor first but then it is being obsoleted, I now am trying to do same by using browser.key but its not working for me.

Please Help !

like image 339
hny2015 Avatar asked Feb 09 '15 12:02

hny2015


1 Answers

i wrote a snippet and tested it against google.de (not .com! maybe you have to adjust this) and when sending TAB the next element gets the focus (in this case it's the search button).

the snippet:

describe('Test', function () {
  it('should browse to google', function () {
    browser.ignoreSynchronization = true;
    browser.driver.get('https://www.google.de');
    expect(browser.getCurrentUrl()).toEqual('https://www.google.de/');
  });
  it('should unfocus the search field', function () {
    var search = element(by.name('q'));
    search.sendKeys(protractor.Key.TAB);
    browser.sleep(3000); // 3s to take a look ;)
  });
});
like image 94
nilsK Avatar answered Sep 30 '22 07:09

nilsK