milos83 Posted July 17, 2017 Share Posted July 17, 2017 (edited) How can I check if element is focused in Firefox using FF.au3 UDF? This is my try: I have prepared a function that checks if the object is focused: _FFCmd('FFau3.isfocused=function isfocused(a){try{return (a === document.activeElement)}catch(e){return}}') $oElm = _FFXPath("//*[@id='someId']") ConsoleWrite(_FFIsFocused($oElm)) Func _FFIsFocused($sElement = "") Local $isFoc = _FFCmd("FFau3.isfocused(" & $sElement & ")") Return $isFoc EndFunc ;==>_FFIsFocused Now, the javascript part is tested and it does return successfully. After a lot of try/fails I inserted an alert box in order to display the object being compared. Here is what I got The focused object is: [object XULElement] The object that I send for comparing is [object HTMLInputElement] Why is that? Edited July 17, 2017 by milos83 Link to comment Share on other sites More sharing options...
Danp2 Posted July 17, 2017 Share Posted July 17, 2017 Have you tried comparing to FFau3.WCD.activeElement instead of document.activeElement ? milos83 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
milos83 Posted July 17, 2017 Author Share Posted July 17, 2017 4 minutes ago, Danp2 said: Have you tried comparing to FFau3.WCD.activeElement instead of document.activeElement ? You nailed it! Thank you Danp2! I'm new to FF.au3 so I didn't know this is the right way to access the document. The final working code is _FFCmd('FFau3.isfocused=function isfocused(a){try{return (a === FFau3.WCD.activeElement)}catch(e){return}}') $oElm = _FFXPath("//*[@id='someId']") ConsoleWrite(_FFIsFocused($oElm)) Func _FFIsFocused($sElement = "") Local $isFoc = _FFCmd("FFau3.isfocused(" & $sElement & ")") Return $isFoc EndFunc ;==>_FFIsFocused Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now