Jump to content
Sign in to follow this  

Send problem in browser tests with no driver plugin or extension (or accessibility)

Recommended Posts


Hi All,

I'm a newbe here so please bare with me.

I'm trying to make a script that will open Chrome (If it is already open set focus to its window) copy the URL from the address-bar and paste it to a new message box.

I understood that I can use or chrome accessibility with code snippets found on this site (or use selenium driver) but I want to be able to compile the script into an exe and run it on different computers.

I wrote a script that sometimes works but sometimes it seems that the keystrokes are not sent to the browser and I cannot understand why. (The window is clearly in focus)

Here is my latest version of the script:

;The idea of the script is to find the window handle of a currently running chrome or open it and then get the handle.

;Using this handle send F6 to the chrome window to go to the address-bar use ^C to copy the url and Clipboard functions to get the copied data.


#include <MsgBoxConstants.au3>
#include <Constants.au3>
#include <Clipboard.au3>


Func GetAppPath($appExe)
    $regPath = "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionApp Paths" & $appExe
    $var = RegRead($regPath, "Path")
    If ($var <> "") Then
        $var = $var & "" & $appExe
        $var = RegRead($regPath, "")
    $var = StringReplace($var, ";", "")
    Return $var
EndFunc   ;==>GetAppPath

Func InfoMsg($msg, $timeout = 0)
    MsgBox($MB_ICONINFORMATION + $MB_SYSTEMMODAL, "Info", $msg, $timeout)
EndFunc   ;==>InfoMsg

Func ErrorMsg($msg, $timeout = 0)
    MsgBox($MB_ICONERROR + $MB_SYSTEMMODAL, "Error In AutoIt Script", $msg, $timeout)
EndFunc   ;==>ErrorMsg

Func ActivateApp($prefixName, $winActivatePath, $openAppBeforeAction)
    $appName = $prefixName & ".exe"
    $appPath = GetAppPath($appName)
    $appWindowsHandle = 0
    If ($appPath = "") Then
        ErrorMsg("Application " & $prefixName & " is not installed")
        ;InfoMsg("Checking " & $prefixName & " active")
        $appWindowsHandle = WinActivate($winActivatePath)
        If ($appWindowsHandle) Then
            If (Not $openAppBeforeAction) Then
                ErrorMsg("Application " & $prefixName & " is not active")
                ;InfoMsg("Running " & $appPath)
                If (Run($appPath)) Then
                    $appWindowsHandle = WinWaitActive($winActivatePath, "", 2)
                    ;InfoMsg("Application " & $prefixName & " is active")
    Return $appWindowsHandle
EndFunc   ;==>ActivateApp

Func GetChromeAdressBarValue($openChromeBeforeAction = 0)
    $abUrl = ""
    $chromeWindowsHandle = ActivateApp("chrome", "[REGEXPCLASS:Chrome*]", 1)
    If ($chromeWindowsHandle) Then
        InfoMsg("Win Handle " & $chromeWindowsHandle & " Getting URL", 1)
        Sleep(2000) ; wait for page load to end
        $chromeWindowsHandle = WinActivate($chromeWindowsHandle)
        If ($chromeWindowsHandle) Then
            $abUrl = _ClipBoard_GetData(1)
            If ($abUrl = "") Then
                InfoMsg("Testing Fullscreen", 1)
                $abUrl = _ClipBoard_GetData(1)
                InfoMsg("Strange: '" & $abUrl & "'", 2)
    Return $abUrl
EndFunc   ;==>GetChromeAdressBarValue

Thanks in advance,


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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.