Jump to content
Marzupilami

Web browser URL checker

Recommended Posts

Marzupilami

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!

Share this post


Link to post
Share on other sites
Exit
#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)

 

  • Like 1

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
Marzupilami

@Exit Thank you very much! Is this possible with Chrome too? With or without AutoIT?

Share this post


Link to post
Share on other sites
MichaelHB
38 minutes ago, Marzupilami said:

Is this possible with Chrome too?

Yes. Look here.

Share this post


Link to post
Share on other sites
Marzupilami
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.

Share this post


Link to post
Share on other sites
MichaelHB

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)

 

Share this post


Link to post
Share on other sites
Marzupilami

@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.

 

#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

 

Share this post


Link to post
Share on other sites
MichaelHB

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.

  • Like 1

Share this post


Link to post
Share on other sites
Marzupilami

Thank you very much for helping me with this @MichaelHB! I would never have figured that out by myself. Now it works :)

Share this post


Link to post
Share on other sites
MichaelHB

You are welcome. :)

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

×