Jump to content
Sign in to follow this  
JohnFromAustralia

Find co-ordinates of a specific tab in a web browser? - (Moved)

Recommended Posts

Hello there,

I am attempting to automate a webbrowser to do a few things for me. One of those things is pinning a specific tab in chrome. There are no keyboard shortcuts to do this, so I need to actually send the mouse there to open up the context menu...

The problem I encounter is, how to find the co-ordinates of the tab? 

Can anyone suggest how I might do that? Is it possible? The text on the tab will be unique, so I could do a text search? I will also know which tab has focus (which is in a variable in my script). I am not sure how I can use either of those bits of information to find the co-ordinates...

Thanks heaps for any thoughts or advice
John

Share this post


Link to post
Share on other sites

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team


"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites

It's not that hard with a little bit of UI Automation code. Here an example with AutoIt Wiki:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#AutoIt3Wrapper_UseX64=y

#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

Example()

Func Example()
  ; 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 )

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

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

  ; --- AutoIt Wiki tab ---

  ; Tab item
  Local $pCondition1
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TabItemControlTypeId, $pCondition1 )
  If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF )
  ConsoleWrite( "$pCondition1 OK" & @CRLF )

  ; Tab name
  Local $pCondition2 ; Note that $UIA_NamePropertyId ia a CASE SENSITIVE condition
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "AutoIt Wiki", $pCondition2 )
  If Not $pCondition2 Then Return ConsoleWrite( "$pCondition2 ERR" & @CRLF )
  ConsoleWrite( "$pCondition2 OK" & @CRLF )

  ; And condition
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF )
  ConsoleWrite( "$pCondition OK" & @CRLF )

  ; Find tab item
  Local $pTab, $oTab
  $oChrome.FindFirst( $TreeScope_Descendants, $pCondition, $pTab )
  $oTab = ObjCreateInterface( $pTab, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oTab ) Then Return ConsoleWrite( "$oTab ERR" & @CRLF )
  ConsoleWrite( "$oTab OK" & @CRLF )

  ; --- Bounding rectangle ---

  Local $sBounds = GetCurrentPropertyValue( $oTab, $UIA_BoundingRectanglePropertyId )
  ConsoleWrite( "Rect = " & $sBounds & @CRLF ) ; l, t, w, h
EndFunc

Func GetCurrentPropertyValue( $oObject, $iPropertyId )
  Local $vValue, $sString
  $oObject.GetCurrentPropertyValue( $iPropertyId, $vValue )
  If Not IsArray( $vValue ) Then Return $vValue
  $sString = $vValue[0]
  For $i = 1 To UBound( $vValue ) - 1
    $sString &= "; " & $vValue[$i]
  Next
  Return $sString
EndFunc

UIAutomation.7z

Edited by LarsJ

Share this post


Link to post
Share on other sites

Also, you can use an extension for Chrome that lets you bind keys to pin/unpin tabs and automate that. There are a few out there - Tab Pinner for example.


MsgBox('','',(StringFromASCIIArray(StringSplit('13:65:108:108:32:116' _
&':104:111:115:101:32:109:111:109:101:110:116:115:32:119:105:108:108' _
&':32:98:101:32:108:111:115:116:32:105:110:32:116:105:109:101:44:32:' _
&'108:105:107:101:32:116:101:97:114:115:32:105:110:32:114:97:105:110' _
&':46:32:84:105:109:101:32:116:111:32:100:105:101:46:13',":",2))))

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...