Jump to content

Getting tooltip text from a Chromium based browser


Recommended Posts

Hello!

I have been trying to get AutoIt to read tooltip text from a Chromium based browser (Yandex broswer, to be precise). I'm 99% sure that this testing code was working on Windows 7, but after updating to Win10 something went wrong. Here's the testing code I am using.

#include <GUIToolTip.au3>

HotKeySet("{ESC}", "Close")
Example()

Func Example()
    While 1
        Sleep(100)
        _Read_Tip()
    WEnd
EndFunc

Func _Read_Tip()
    Local $aTipList = WinList("[CLASS:tooltips_class32]")
    Local $aRet
    For $i = 1 To $aTipList[0][0]
        If WinGetProcess($aTipList[$i][1]) = WinGetProcess("[ACTIVE]") Then
            $aRet = _GUIToolTip_GetCurrentTool($aTipList[$i][1])
            If $aRet[8] <> "" Then MsgBox(0, "Visible Tip", $aRet[8])
        EndIf
    Next
EndFunc 

Func Close()
    Exit
EndFunc

This code does catch some of the other programmes' tooltips though. I think the source of the problem that some tooltips are not actually windows of class "tooltips_class32" (for instance, Total Commander's tooltips). How does one intercept such tooltips? I tried to catch them with Au3Info, UIASpy without success.

I have tried tons of different browsers and they all seem to be working same way. With the exception of IE11, but for some reason it won't open the page I'm trying to automate.

Link to comment
Share on other sites

It only works on Win7 and IE.   Tested on other combinations, it doesn't work otherwise.  Also your code was not working, so this is the code that I used :

#include <GUIToolTip.au3>
#include <Array.au3>

HotKeySet("{ESC}", "Close")

Example()

Func Example()
  While 1
    Sleep(300)
    _Read_Tip()
  WEnd
EndFunc   ;==>Example

Func _Read_Tip()
  Local $aTipList = WinList("[CLASS:tooltips_class32]")
  Local $aRet
  For $i = 1 To $aTipList[0][0]
    If BitAND(WinGetState($aTipList[$i][1]), $WIN_STATE_VISIBLE) Then
      $aRet = _GUIToolTip_GetCurrentTool($aTipList[$i][1])
      If $aRet[0] <> 0 Then ConsoleWrite("found" & "/" & $aRet[8] & @CRLF)
    EndIf
  Next
EndFunc   ;==>_Read_Tip

Func Close()
  Exit
EndFunc   ;==>Close

 

Edited by Nine
Link to comment
Share on other sites

So basically there is no easy way to do that on win10? I mean there should be some way to read these tooltips via OCR, but that seems like an overkill. 

I also tried looking through everything generated by WinList(), but there were no windows with class similar to browser's one. 

Link to comment
Share on other sites

5 minutes ago, ZeroToHero said:

but there were no windows with class similar to browser's one

Yes that is what I also found.  The class only appears under Win7 AND under IE.

But I believe you could use UIAutomation to read those tooltips, although I did not test it.   Before investing too much time into it, just use UIA spy to see if it can identify the tooltip.

Link to comment
Share on other sites

Here to start you up (couldn't help trying it) ;)

#include <Constants.au3>
#include "Includes\CUIAutomation2.au3"

Opt("MustDeclareVars", 1)

Example()

Func Example()
  ; Create UI Automation object
  Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)
  If Not IsObj($oUIAutomation) Then Return ConsoleWrite("$oUIAutomation ERR" & @CRLF)
  ConsoleWrite("$oUIAutomation OK" & @CRLF)

  ; Get Desktop element
  Local $pDesktop, $oDesktop
  $oUIAutomation.GetRootElement($pDesktop)
  $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oDesktop) Then Return ConsoleWrite("$oDesktop ERR" & @CRLF)
  ConsoleWrite("$oDesktop OK" & @CRLF)

  ; --- Find Chrome window ---

  Local $pCondition
  $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Chrome_WidgetWin_1", $pCondition)
  If Not $pCondition Then Return ConsoleWrite("$pCondition ERR" & @CRLF)
  ConsoleWrite("$pCondition OK" & @CRLF)

  Local $pChrome, $oChrome
  $oDesktop.FindFirst($TreeScope_Descendants, $pCondition, $pChrome)
  $oChrome = ObjCreateInterface($pChrome, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oChrome) Then Return ConsoleWrite("$oChrome ERR" & @CRLF)
  ConsoleWrite("$oChrome OK" & @CRLF)

    ; --- Find Tooltip element ---

  $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "tooltips_class32", $pCondition)
  If Not $pCondition Then Return ConsoleWrite("$pCondition ERR" & @CRLF)
  ConsoleWrite("$pCondition OK" & @CRLF)

  Local $pTooltip, $oTooltip
  While True
    $oDesktop.FindFirst($TreeScope_Descendants, $pCondition, $pTooltip)
    $oTooltip = ObjCreateInterface($pTooltip, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
    If IsObj($oTooltip) Then ExitLoop
  WEnd

  ConsoleWrite ("Found tooltip" & @CRLF)

  Local $sText
  $oTooltip.GetCurrentPropertyValue($UIA_NamePropertyId, $sText)    ; $UIA_NamePropertyId extracts the text
  MsgBox ($MB_SYSTEMMODAL,"",$sText)

EndFunc

Works perfectly on Win7.  Cannot test it on Win10, I do not have Chrome. I'll see if I have time to test it on Win10/Edge later...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...