Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send keys to the element in focus?

In my tests I have a number of modals and dropdowns which open and automatically have focus set on their input boxes.

I have seen that it is possible to assert that an element is in focus. But is there any shortcut way to send keys to the element currently in focus? I'd like to be able to skip all the work of finding each element every time.

like image 887
Niel Avatar asked Oct 23 '15 17:10

Niel


1 Answers

You can use activeElement() feature of selenium to access the currently focused element source.

E.g.

// select the current page context's active element
browser.switchTo().activeElement().sendKeys('Test')
like image 199
Nick Tomlin Avatar answered Sep 16 '22 14:09

Nick Tomlin