milos83

FF.au3 how to check if element is focused?

3 posts in this topic

#1 ·  Posted (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 by milos83

Share this post


Link to post
Share on other sites



#2 ·  Posted

Have you tried comparing to

FFau3.WCD.activeElement

instead of

document.activeElement

?

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • Marc
      By Marc
      Profiler - yet another backup script for Firefox and Thunderbird profiles
      It automatically detects the last recently used profile directories of Firefox and Thunderbird (installed versions, no portables).
      Clicking the Backup-Button creates a complete Backup of the found profiles with a timestamp.
      Restore deletes the according profile dir and extracts the content of the selected archive into the profile directory.
      Uses Winrar as compression tool, but feel free to change it to your needs
      Best regards
      Marc

      Profiler.au3
    • BOUNCER
      By BOUNCER
      I'm trying to get the output data from https://www.guilded.gg but it uses a web app that generates that output on the fly and this doesn't show up in the page source.
      Only in web inspector of each browser does this data show up. How do I read this data in autoit (equivalent to the web inspector)
       
      thank you
    • ur
      By ur
      We can select elements in IE using their IDs as below.
      Local $oDiv = _IEGetObjById($oIE, "x-auto-16-input") But to one button in the webpage, there is no ID to it.
      In selenium we have option to select this element using the CssSelector and clicked the button using below code in c# selenium.
      driver.FindElement(By.CssSelector("button.x-btn-text")).Click(); What is the alternative for this in AUtoIT?
    • Patryk
      By Patryk
      Dear Colleagues,
      I have no idea how to refer to style.display in my loop. There is a button like: 
      <input name="ctl00$bodyPlaceholder$btnFecharProcessamento" class="button" id="bodyPlaceholder_btnFecharProcessamento" style="display: none;" onclick="FecharJanelaProcessamento();return false;" type="submit" value="Fechar"> I want it to be clicked as soon as button's style change from style="display: none;" to  style= ="display: inline-block;" 
      This is what I got, but it's not working...
      Func GetButtons() $oButtons = _IEGetObjByName($oForm,"ctl00$bodyPlaceholder$btnFecharProcessamento",-1) $i = 0 While $i <> 1 For $oBtn In $oButtons If _IEFormElementGetValue($oBtn) = "Fechar" And $oBtn.document.style.display = "display: inline-block;" Then $i = 1 _IEAction($oBtn, "focus") _IEAction($oBtn, "click") ExitLoop EndIf Next WEnd EndFunc  
      I will really appreciate if you could help me with these loop!
    • Pao
      By Pao
      Hello, I've recently updated from Firefox 50 to 54.0.1.
      My Autoit script that previously worked fine, now seems to have erratic problems.
      It's almost as if some Send() commands are sometimes skipped when dealing with the Firefox UI (it's still mostly fine on the actual pages).

      To temporarly fix the problem, I had to put some Sleep(200) pauses and avoid grouping keys together (e.g: TAB 2), but I'm not exactly sure about the correct way to deal with this..
      Could this be caused by the new multiprocess feature? (e10s)
      Are there better Autoit commands or rules that I should use?