最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to send keys to the element in focus? - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a comment  | 

2 Answers 2

Reset to default 15

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')

Alternatively, you may use "browser actions":

browser.actions().sendKeys('Test').perform();
发布评论

评论列表(0)

  1. 暂无评论