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.
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.
Share Improve this question edited Oct 23, 2015 at 22:19 alecxe 474k126 gold badges1.1k silver badges1.2k bronze badges asked Oct 23, 2015 at 17:08 NielNiel 2,0064 gold badges24 silver badges46 bronze badges2 Answers
Reset to default 15You 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')
Alternatively, you may use "browser actions":
browser.actions().sendKeys('Test').perform();