4Eyes Posted January 28, 2011 Posted January 28, 2011 Folks, I've been trying to read the current URL from Chrome for some time and tried a few different approaches but with little success, however, I see that Au3Info.exe (the window info tool) does this. I.E. with Chrome open and displaying say www.google.com, start Au3Info, choose the 'Visible Text' tab in Au3Info and you see the title of the tab and on the 2nd line, the url. My latest attempt is this: $Title = WinGetTitle("[CLASS:Chrome_WidgetWin_0]", "") ConsoleWrite("Tab title = '" & $Title & "'" & @CRLF) ConsoleWrite("Text = " & ControlGetText($Title, "", "[CLASS:Chrome_AutocompleteEditView]") & @CRLF) ConsoleWrite("Text = " & ControlGetText($Title, "", "[CLASS:Chrome_WidgetWin_0]") & @CRLF) but it doesn't work. It occasionally shows an incorrect title, but never any text. Before anybody asks, I want this specifically for Chrome, not Firefox or IE. Any help would be appreciated as I'd love to put this to bed once and for all. I have such a love/hate relationship with Chrome. Grrr! It's an odd beast to be sure. 4Eyes
Skitty Posted January 28, 2011 Posted January 28, 2011 (edited) This should get you started.AutoItSetOption("WinTitleMatchMode", 2) If @error Then Exit $1 = WinWaitActive(ControlGetText("[CLASS:Chrome_WidgetWin_0]", " ", WinGetTitle("[CLASS:Chrome_WidgetWin_0]"))) If @error Then MsgBox(0,"","FAIL!!!!") Else MsgBox(0, "", ControlgetText($1, "", "Chrome_AutocompleteEditView1" )) EndIfThe code gives you the tab URL when you activate chrome. Edited January 28, 2011 by xJSLRx
Varian Posted January 28, 2011 Posted January 28, 2011 (edited) Try this...Chrome has one blank window and if you select the tab that is not focused, you cannot get the text from the address bar. Test by switching the active tab and run the script $List = WinList("[REGEXPCLASS:Chrome_WidgetWin_0]") If Not IsArray($List) Then Exit ;Exit if Chrome is not open For $i = 1 To $List[0][0] If Not WinGetTitle($List[$i][1]) Then ContinueLoop ;skip balnk Chrome Window If Not ControlGetText($List[$i][1], "", "[CLASS:Chrome_AutocompleteEditView]") Then ContinueLoop ;if Active Tab is not seleceted, Text will be blank so skip $Title = WinGetTitle($List[$i][1]) $TabTitle = ControlGetText($Title, "", "[CLASS:Chrome_WidgetWin_0]") $TabURL = ControlGetText($Title, "", "[CLASS:Chrome_AutocompleteEditView]") ExitLoop Next ConsoleWrite("Window Title = " & $Title & @CRLF) ConsoleWrite("Tab Title = " & $TabTitle & @CRLF) ConsoleWrite("Tab URL = " & $TabURL & @CRLF) Edited January 28, 2011 by Varian
Varian Posted January 28, 2011 Posted January 28, 2011 (edited) Here is a much better example. This is a fluid display #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #region ### START Koda GUI section ### Form= $Form1 = GUICreate("Result Window", 600, 184, -1, -1, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE)) $Edit = GUICtrlCreateEdit("", 0, 0, 600, 201, $ES_WANTRETURN) GUICtrlSetFont(-1, 13) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 If GUICtrlRead($Edit) <> _GetChromeText() Then GUICtrlSetData($Edit, _GetChromeText()) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _GetChromeText() Local $Title, $TabTitle, $TabURL Local $List = WinList("[REGEXPCLASS:Chrome_WidgetWin_0]") If Not IsArray($List) Then Exit For $i = 1 To $List[0][0] If Not WinGetTitle($List[$i][1]) Then ContinueLoop If Not ControlGetText($List[$i][1], "", "[CLASS:Chrome_AutocompleteEditView]") Then ContinueLoop $Title = WinGetTitle($List[$i][1]) $TabTitle = ControlGetText($Title, "", "[CLASS:Chrome_WidgetWin_0]") $TabURL = ControlGetText($Title, "", "[CLASS:Chrome_AutocompleteEditView]") ExitLoop Next Return "Window Title = " & $Title & @CRLF & @CRLF & "Tab Title = " & $TabTitle & @CRLF & @CRLF & "Tab URL = " & $TabURL EndFunc ;==>_GetChromeText EDIT:I forgot to declare variables in the function..the script would break on a blank tab or the "New Tab" page. Fixed that now. Edited January 28, 2011 by Varian
4Eyes Posted January 28, 2011 Author Posted January 28, 2011 xJSLRx, Thanks for your reply although it didn't help. Varian, That hits the spot. Thank you. I tried getting window titles with WinList() and comparing PIDs obtained via ProcessList() but it was a nightmare and didn't work well at all. It looks like I was poking around the edges but just couldn't make it happen. Thanks for your efforts, much appreciated. Now, if I could just win 1 game of MineSweeper in expert mode I could die a happy man. Regards, 4Eyes
Skitty Posted January 28, 2011 Posted January 28, 2011 (edited) xJSLRx, Thanks for your reply although it didn't help. Varian, That hits the spot. Thank you. I tried getting window titles with WinList() and comparing PIDs obtained via ProcessList() but it was a nightmare and didn't work well at all. It looks like I was poking around the edges but just couldn't make it happen. Thanks for your efforts, much appreciated. Now, if I could just win 1 game of MineSweeper in expert mode I could die a happy man. Regards, 4Eyes No problem, It helped me! This is an interesting subject and the code I wrote will be pretty useful, especially the navigation part. AutoItSetOption("WinTitleMatchMode", 2) If @error Then Exit While 1 $0 = ControlGetText("[CLASS:Chrome_WidgetWin_0]", " ", WinGetTitle("[CLASS:Chrome_WidgetWin_0]")) If $0 = "" Then ContinueLoop Else $T = ControlgetText($0, "", "Chrome_AutocompleteEditView1") IniWrite(@ScriptDir & "\URL.ini","Chrome","URL",$T) _1() EndIf WEnd Func _1();This is supposed to check if the url from the ini file differs to the current url While 1 $x = ControlgetText($0, "", "Chrome_AutocompleteEditView1") $TT = IniRead(@ScriptDir & "\URL.ini","Chrome","URL",$T) MsgBox(0, "", $T) If $x = $TT Then ContinueLoop Else ExitLoop EndIf WEnd EndFunc What Im aiming for is recording every url I visit but It still has some bugs, the code above doesn't work but should tell you exactly what I am doing. I'll update it when I finish cause i'm sure some one's gonna get here later via Google and having a larger variety per post is good isn't it? Edit: No, stick with varian's code or you can edit mine to actually work if my first post's code does not suit you need's. I'm currently encrypting a script and am too into it. I'll look into Chrome's url logging later Edited January 28, 2011 by xJSLRx
4Eyes Posted January 28, 2011 Author Posted January 28, 2011 xJSLRx, Certainly, variety is the spice of life and there always seems to be more than one way to skin a cat. If you need to get url's from IE etc as well then there's been some good examples posted here recently. 4Eyes
baconismidog Posted January 12, 2014 Posted January 12, 2014 Sorry to necro this thread but this method, using [CLASS:Chrome_AutocompleteEditView], doesn't seem to work anymore. I don't want to resort to control sending an F6 or !d to highlight the URL bar and clipget to read it - that seems like it would be prone to failure in certain instances. Is there any other way to do it besides the ghetto way I've mapped out above? Thanks guys (and sorry again for the necro but this is the most promising thread I've found).
LarsJ Posted January 12, 2014 Posted January 12, 2014 Take a look at the UI Automation framework. In particular, examples 5 and 6 in the list near the bottom of the first post. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
BlackSnoww Posted April 20, 2019 Posted April 20, 2019 @Skitty i know its been a long time but does this code still works for you ? AutoItSetOption("WinTitleMatchMode", 2) If @error Then Exit While 1 $0 = ControlGetText("[CLASS:Chrome_WidgetWin_0]", " ", WinGetTitle("[CLASS:Chrome_WidgetWin_0]")) If $0 = "" Then ContinueLoop Else $T = ControlgetText($0, "", "Chrome_AutocompleteEditView1") IniWrite(@ScriptDir & "\URL.ini","Chrome","URL",$T) _1() EndIf WEnd Func _1();This is supposed to check if the url from the ini file differs to the current url While 1 $x = ControlgetText($0, "", "Chrome_AutocompleteEditView1") $TT = IniRead(@ScriptDir & "\URL.ini","Chrome","URL",$T) MsgBox(0, "", $T) If $x = $TT Then ContinueLoop Else ExitLoop EndIf WEnd EndFunc I tried using it but it seems it cant read my chrome
junkew Posted April 21, 2019 Posted April 21, 2019 As said before bij lars uia will give you this info for all browsers in a similar way. Examples in uia cover ff ie edge chrome safari opera browsers. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
BlackSnoww Posted April 22, 2019 Posted April 22, 2019 Sorry but the UI automaton is too advance for me to understand. I just started using autoit not so long ago
junkew Posted April 23, 2019 Posted April 23, 2019 Just start with simplespy it gives some sample code when you spy the addressbar. @LarsJ wrote a very detailed thread on how to use uia will add that link to faq31 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
junkew Posted April 29, 2019 Posted April 29, 2019 Use simplespy to see base hierarchy Observation which can be hard is that you do not get the editbox This is normally where inspect.exe shows you a better hierarchy Copy paste the code Run it step by step by adding exit after a _UIA_Action line and if its not highlighting your recognition string is incorrect Hard observation is here that you need to use a pane by index as there is not title This is normally where inspect.exe helps you out Get your value of the edit box Clean up the code by remove empty properties shorten controltype remove highlighting steps example code ;~ *** Standard code maintainable *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=.*Google Chrome;controltype:=Pane;class:=Chrome_WidgetWin_1") ;Find control with ID and other property - AutoIt General Help and Support - AutoIt Forums - Google Chrome _UIA_setVar("oP2","Title:=Google Chrome;controltype:=Pane") ;Google Chrome _UIA_setVar("oP3","controltype:=Pane;index:=2") ; _UIA_setVar("oP4","controltype:=Pane") ; _UIA_setVar("oP5","controltype:=Pane") ; _UIA_setVar("oP6","controltype:=Group;class:=") ; ;~ $oUIElement=_UIA_getObjectByFindAll(".mainwindow", "title:=;ControlType:=UIA_PaneControlTypeId", $treescope_subtree) ;~ _UIA_setVar("oUIElement","Title:=;controltype:=UIA_PaneControlTypeId;class:=") ;ControlType:=UIA_PaneControlTypeId;classname:=") _UIA_setVar("oUIElement","controltype:=Edit") ;ControlType:=UIA_PaneControlTypeId;classname:=") ;~ Actions split away from logical/technical definition above can come from configfiles _UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") _UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") _UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") _UIA_Action("oP4","highlight") _UIA_Action("oP4","setfocus") _UIA_Action("oP5","highlight") _UIA_Action("oP5","setfocus") _UIA_Action("oP6","highlight") _UIA_Action("oP6","setfocus") _UIA_action("oUIElement","highlight") _UIA_action("oUIElement","click") consolewrite(_UIA_action("oUIElement","getvalue")) FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
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