3

I'm testing a site (in Chrome) that has a "spotlight search" feature like on Macs, where an input shows up when you press a certain key. There is a directive that takes care of the logic for this, and you can type anywhere in the application, as long as it's not an input. I need to test this feature by sending keys through my protractor tests, but I get unknown error: cannot focus element when I target a div. Is it possible to send keys on an element that isn't an input?

2
  • Possibly related: stackoverflow.com/questions/21991003/… Commented Jul 28, 2015 at 22:36
  • I am already using browser.ignoreSynchronization and browser.sleep(5000) as that answer suggests, still have the same problem Commented Jul 28, 2015 at 22:44

1 Answer 1

8

You would probably need to wait for the element to become visible with a visibilityOf Expected Condition and browser.wait():

var EC = protractor.ExpectedConditions; browser.wait(EC.visibilityOf(by.css("div#myid")), 5000); var div = element(by.css("div#myid")); div.sendKeys("test"); 

Also, you can try utilizing browser.actions():

browser.actions().mouseMove(div).sendKeys('test').perform(); 

Also, you may need to click the element before sending keys:

div.click().sendKeys("test"); 
Sign up to request clarification or add additional context in comments.

1 Comment

browser.actions().mouseMove(div).sendKeys('test').perform(); was the one that worked for me. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.