Selenium IDE: How to check if an element has a focus?

断了今生、忘了曾经 提交于 2019-12-22 05:30:11

问题


Is there a built in method for checking that an input text element has a focus ?

Well, I didn't find one, so I tried this extension.

But, it doesn't work for me either (i.e. the test fails).

Any ideas ?


回答1:


I have had numerous problems detecting if an element has focus because the browser Selenium is controlling typically does not have the focus within the Operating System, and as such the browser will NOT consider any elements to have focus until the browser regains the focus.

I have been pulling my hair out over this, so worked up a solution to this problem. See http://blog.mattheworiordan.com/post/9308775285/testing-focus-with-jquery-and-selenium-or for a full explanation of the problem and a solution to this.

If you can't be arsed to read the lengthy explanation, simply include https://gist.github.com/1166821 BEFORE you include JQuery, and use $(':focus') to find the element that has focus, or .is(':focus') to check if an element has focus.




回答2:


I wrote that plugin and it is working fine in my environment. Could you provide me a detailed description of how you used it? I would try bugfix it if we will find a bug.



来源:https://stackoverflow.com/questions/5400708/selenium-ide-how-to-check-if-an-element-has-a-focus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!