Marzupilami Posted May 24, 2016 Share Posted May 24, 2016 Hi everybody, Is there a way using AutoIT script to check what URL I have currently open in my web browser? (Any browser is fine, but preferrably Chrome.) An then put it to a variable like: if $url = "https://www.autoitscript.com/forum/" then ... etc. Thanks! Link to comment Share on other sites More sharing options...
Exit Posted May 25, 2016 Share Posted May 25, 2016 #include <IE.au3> $oIE = _IECreate() _IEBodyWriteHTML($oIE, "Now navigate to your desired Web-Page") MsgBox(64 + 262144, Default, "Click OK when disired Web-Page is active", 0) $sURL = _IEPropertyGet($oIE, "locationurl") $sName = _IEPropertyGet($oIE, "locationname") MsgBox(64 + 262144, Default, $sURL & @LF & $sName, 0) _IEQuit($oIE) Marzupilami 1 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Marzupilami Posted May 28, 2016 Author Share Posted May 28, 2016 @Exit Thank you very much! Is this possible with Chrome too? With or without AutoIT? Link to comment Share on other sites More sharing options...
MichaelHB Posted May 28, 2016 Share Posted May 28, 2016 38 minutes ago, Marzupilami said: Is this possible with Chrome too? Yes. Look here. Link to comment Share on other sites More sharing options...
Marzupilami Posted June 3, 2016 Author Share Posted June 3, 2016 On 2016-05-28 at 10:04 PM, MichaelHB said: Yes. Look here. Thanks for that. Though, I'm really a beginner so I don't understand very much of what it does. Could you please explain to me or take out only the strings of code that I need? I've tried for a while now, and I can make it work partly. Though it dumps xml files to my desktop every time I run the code, which is very annoying! How do I get rid of that? And how do I get the simpliest possible code? Thank you for your help. Link to comment Share on other sites More sharing options...
MichaelHB Posted June 3, 2016 Share Posted June 3, 2016 Marzupilami, Let me see what you have tried so far. In the link there is an example that junkew made and the code is commented. Look for the part ";~ get the value of the addressbar". To stop the xml and highlight use this: (this information can found in the forum search) _UIA_setVar("Global.Debug", False) _UIA_setVar("Global.Debug.File", False) _UIA_setVar("Global.Highlight", False) Link to comment Share on other sites More sharing options...
Marzupilami Posted June 3, 2016 Author Share Posted June 3, 2016 @MichaelHB This is what I have right now. Modified the script you linked as long as it was working, have no idea what I'm doing though. It didn't work what you said to stop the xml dumping! Tried to change it to false in the UIAWrappers.au3 file as well, but it didn't work then either. I am very thankful for all help with this. expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <constants.au3> #include <WinAPI.au3> #include <debug.au3> #include "CUIAutomation2.au3" #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=Y ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os _UIA_setVar("Global.Debug", False) _UIA_setVar("Global.Debug.File", False) _UIA_setVar("Global.Highlight", False) Global $myText If ProcessExists("chrome.exe") Then _getaddressbar() Else Run("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe") ProcessWait("chrome.exe") Sleep(3000) _getaddressbar() EndIf Func _getaddressbar() $oChrome=_UIA_getFirstObjectOfElement($UIA_oDesktop,"class:=Chrome_WidgetWin_1", $treescope_children) $oChromeAddressBar=_UIA_getFirstObjectOfElement($oChrome,"controltype:=" & $UIA_EditControlTypeId , $treescope_subtree) ;works in chrome 29 $oValueP=_UIA_getpattern($oChromeAddressBar,$UIA_ValuePatternId) $myText="" $oValueP.CurrentValue($myText) EndFunc MsgBox(64 + 262144, Default, $myText) Exit Link to comment Share on other sites More sharing options...
MichaelHB Posted June 3, 2016 Share Posted June 3, 2016 I knew you could make it work. I dont know if you need all the includes. Almost the same as yours: #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=Y ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os _UIA_setVar("Global.Debug", False) _UIA_setVar("Global.Debug.File", False) _UIA_setVar("Global.Highlight", False) If Not ProcessExists("chrome.exe") Then Run("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe") ProcessWait("chrome.exe") Sleep(3000) EndIf MsgBox(0, "", _getaddressbar()) Func _getaddressbar() Local $oChrome, $oChromeAddressBar, $oValueP, $sURL $oChrome = _UIA_getFirstObjectOfElement($UIA_oDesktop, "class:=Chrome_WidgetWin_1", $treescope_children) If Not IsObj($oChrome) Then Exit ConsoleWrite("Error in $oChrome" & @CRLF) $oChromeAddressBar = _UIA_getFirstObjectOfElement($oChrome, "controltype:=" & $UIA_EditControlTypeId , $treescope_subtree) If Not IsObj($oChromeAddressBar) Then Exit ConsoleWrite("Error in $oChromeAddressBar" & @CRLF) $oValueP = _UIA_getpattern($oChromeAddressBar, $UIA_ValuePatternId) If Not IsObj($oValueP) Then Exit ConsoleWrite("Error in $oValueP" & @CRLF) $sURL = "" $oValueP.CurrentValue($sURL) Return $sURL EndFunc Exit To stop the logs, go to the "UIAWrappers.au3" file and comment the 2 functions like this: (line 1570 and 1583) func _UIA_LogFile($strName="log.xml", $reset=false) ;~ if $reset=true Then ;~ $__g_hFileLog=fileopen($strName, $FO_OVERWRITE + $FO_UTF8) ;~ filewrite($__g_hFileLog,"<?xml version=""1.0"" encoding=""UTF-8""?>") ;~ filewrite($__g_hFileLog,"<log space=""preserve"">") ;~ ;;~ filewrite($__g_hFileLog,"<!DOCTYPE html><html><body>") ;~ ;;~ filewrite($__g_hFileLog,"<h1>UIA logging</h1>") ;~ Else ;~ $__g_hFileLog=fileopen($strName,$FO_APPEND + $FO_UTF8) ;~ EndIf EndFunc func _UIA_LogFileClose() ;~ ;;~ filewrite($__g_hFileLog,"</body></html>") ;~ filewrite($__g_hFileLog,"</log>" & @CRLF) ;~ fileclose($__g_hFileLog) EndFunc This will stop the log file, if you need it back just take the comment off. I dont know why the log dont stop after the "_UIA_setVar("Global.Debug.File", False)". I will try to look this later. Marzupilami 1 Link to comment Share on other sites More sharing options...
Marzupilami Posted June 4, 2016 Author Share Posted June 4, 2016 Thank you very much for helping me with this @MichaelHB! I would never have figured that out by myself. Now it works Link to comment Share on other sites More sharing options...
MichaelHB Posted June 4, 2016 Share Posted June 4, 2016 You are welcome. Link to comment Share on other sites More sharing options...
Ivo Posted January 23, 2020 Share Posted January 23, 2020 On 6/3/2016 at 8:02 PM, Marzupilami said: @MichaelHB This is what I have right now. Modified the script you linked as long as it was working, have no idea what I'm doing though. It didn't work what you said to stop the xml dumping! Tried to change it to false in the UIAWrappers.au3 file as well, but it didn't work then either. I am very thankful for all help with this. expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <constants.au3> #include <WinAPI.au3> #include <debug.au3> #include "CUIAutomation2.au3" #include "UIAWrappers.au3" #AutoIt3Wrapper_UseX64=Y ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os _UIA_setVar("Global.Debug", False) _UIA_setVar("Global.Debug.File", False) _UIA_setVar("Global.Highlight", False) Global $myText If ProcessExists("chrome.exe") Then _getaddressbar() Else Run("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe") ProcessWait("chrome.exe") Sleep(3000) _getaddressbar() EndIf Func _getaddressbar() $oChrome=_UIA_getFirstObjectOfElement($UIA_oDesktop,"class:=Chrome_WidgetWin_1", $treescope_children) $oChromeAddressBar=_UIA_getFirstObjectOfElement($oChrome,"controltype:=" & $UIA_EditControlTypeId , $treescope_subtree) ;works in chrome 29 $oValueP=_UIA_getpattern($oChromeAddressBar,$UIA_ValuePatternId) $myText="" $oValueP.CurrentValue($myText) EndFunc MsgBox(64 + 262144, Default, $myText) Exit Thanks. This is what I am looking for!!! Ivo 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