I can't activate the "File Open" window on Chrome and Edge

6 posts in this topic

#1 ·  Posted (edited)

Hi, I'm trying to upload a file with a web browser but I can't select the Open File window to select the file that I want to upload.

TL;DR I can't handle the Open File window of Chrome and MS Edge. AutoIt just doesn't find it by its title (in Firefox yes, but not on Chrome and MS Edge).

With another software (Selenium Webdriver in Python) I access to a web page with a common HTML5 file uploader and I click on it, but when the Open File window comes up, I want to select a file and press Enter (write the filepath that I give and press Enter key or Open button).

I have the idea, and I have the script on AutoIt too... but it doesn't work on Windows Edge and Chrome, only works on Firefox and Pale Moon (who are basically the same).

Here is my code:

#include <MsgBoxConstants.au3>
$title = "Abrir" ; My Windows is in spanish, but I guess it's "Open" in English and it's the same code
If WinActive($title) Then
    MsgBox($MB_SYSTEMMODAL, "WinActive", "Window not found.")

In Firefox (and Pale Moon) the Open File window comes up, the file path is written and the Enter key is pressed. It works perfect.

In Chrome and Edge, I never see the Open File window on top... and I neither see "Window not found" message (seems like AutoIt finds it but doesn't send keys).

Edit: before to send this post, I started thinking again and... after several tests, I discovered one thing: when you select the window, in Firefox (and Pale Moon) the cursor goes to the combobox (where I have to put the text) and it's possible to write just after clicking (or opening, what in AutoIt it is "Activate" I guess) the window but in Chrome and Edge it isn't like that, when you click the window, the cursor doesn't go to the combobox.

With that "discovery", I tried to select the combobox but... I failed again. And now I have no idea how to go ahead.

#include <MsgBoxConstants.au3>
$title = "Abrir"
If WinActive($title) Then
    ControlClick($title, "", 1148) ; Still it does not work
    MsgBox($MB_SYSTEMMODAL, "WinActive", "Window not found.")


Edited by Rhazz

Share this post

Link to post
Share on other sites

#2 ·  Posted (edited)

My cat asked :" Did Rhazz try Control - o " ?

Edited by PACaleala

Share this post

Link to post
Share on other sites
On 2/8/2016 at 7:37 AM, PACaleala said:

My cat asked :" Did Rhazz try Control - o " ?

Sorry mate, but I don't understand.

Control+O opens the "File Open" window... but I'm asking about how to use that window on Chrome and Edge, where at the moment I can't find this window (I mean handle with AutoIt), to write the file directory and use the open button.

AutoIt just doesn't find the window by its title, and so I can't use it.

Share this post

Link to post
Share on other sites

#5 ·  Posted (edited)

Hello. Hola


Probably something like this could do the trick.


#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Process.au3>
#include <Misc.au3>
#include <WinAPIProc.au3>
#include <Array.au3>
Global $hDLL, $hWinEventProc, $hHook

HotKeySet("{ESC}", "_HotKey") ; Exit

MsgBox(0,"How To Use:","Just Open A Chrome Tab Press CTRL+O And you will get a File Loaded",5)

Global Const $sFile=@DesktopDir & "\DemoFile.txt"
FileWrite($sFile,"Hola Soy Danyfirex")

Global Const $EVENT_SYSTEM_DIALOGSTART = 0x0010 ;An MSAA event indicating that a dialog box was displayed.


$hDLL = DllOpen("User32.dll")
$hWinEventProc = DllCallbackRegister("_WinEventProc", "none", "hwnd;int;hwnd;long;long;int;int")
If Not @error Then
    MsgBox(16 + 262144, "Error", "DllCallbackRegister(_WinEventProc) did not succeed.")

$hHook = _SetWinEventHook($EVENT_Min, $EVENT_Max, $hDLL)

While 1

Func _WinEventProc($hHook, $iEvent, $hWnd, $idObject, $idChild, $iEventThread, $iEventTime)
    Local $PID = WinGetProcess($hWnd)
    Local $sEventProcName = _ProcessGetName($PID)

    If StringInStr(WinGetTitle($hWnd), "abrir") And $sEventProcName="chrome.exe" Then
        MsgBox(0,"Information","Google Chrome Dialog Detected" & @CRLF & _
        "Load A File For testing..." & @CRLF,3)

EndFunc   ;==>_WinEventProc

Func _SetWinEventHook($iEventMin, $iEventMax, $hDLLUser32)

    Local $aRet=0
    Local Const $WINEVENT_OUTOFCONTEXT = 0x0
    If Not $hDLLUser32 Or $hDLLUser32 = -1 Then $hDLLUser32 = "User32.dll"
    $aRet = DllCall($hDLLUser32, "hwnd", "SetWinEventHook", _
            "uint", $iEventMin, _
            "uint", $iEventMax, _
            "hwnd", 0, _
            "ptr", DllCallbackGetPtr($hWinEventProc), _
            "int", 0, _
            "int", 0, _
    If @error Then Return SetError(@error, 0, 0)
    Return $aRet[0]
EndFunc   ;==>_SetWinEventHook

Func _HotKey()
    Switch @HotKeyPressed
        Case "{ESC}"
EndFunc   ;==>_HotKey

Func OnAutoItExit()
    If $hWinEventProc Then
    If $hHook Then DllCall("User32.dll", "int", "UnhookWinEvent", "hwnd", $hHook)
    If $hDLL Then DllClose($hDLL)
EndFunc   ;==>OnAutoItExit


Edit: This is for chrome. If you want to handle MS Edge Check line 45.


Edited by Danyfirex

Share this post

Link to post
Share on other sites

Another option is to use a command like this :

Run('"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files "L:\my_image.jpg"')


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

  • Similar Content

    • fenhanxue
      By fenhanxue
      Q 1:
      How to judge whether the Chrome has been installed. How to get the complete route of chrome if it is installed?

      Q 2:
      How to judge whether the Adobe Flash Player has been installed.
    • FMS
      By FMS
      I'm trying to wright a automated process to show some URL's in chrome browsers on multiple screens.
      I've 4 screens and want to show on each screen another instance of chrome whit its own URL.
      In mine search on the site i din't find any topic for this specific problem.
      The way I was trying is something like :
      ShellExecute("chrome.exe", "http://URL1 --start-maximized") so I'll not see the addressbar but it was not opend full screen .
      I've some questions about this way:
      -Is there a way to maximize it on a dedicated screen ?
      (like URL1 on screen 1 , URL2 on screen 2 etc...)
      -Shellexecute will add a tab on a existing browser and will not open another instance, is there a way to work around this?
      Is there somebody who had the same problem whit chrome?
      thanks in advanced.
      edit: I've checked the chrome UDF but it din't same to get the job done....
    • BlazerV60
      By BlazerV60
      Hello all,
      I've been trying to figure out how to launch Google Chrome in the background (hidden) but it doesn't seem possible. I've tried the following methods:
      ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "", "", "", @SW_HIDE) Also I've tried:
      ShellExecute(@ComSpec, "/c start chrome.exe","","",@SW_HIDE) Lastly I tried:
      RunWait('"'&@ProgramFilesDir&'\Google\Chrome\Application\chrome.exe" --silent-launch',@ScriptDir)  
      But all of them launch my chrome browser without hiding it. Does anyone know a workaround for this or if AutoIT just can't Chrome? 
      Bonus points if you know how to make it launch chrome hidden and make it go to https://www.autoitscript.com
      Thank you,
      By BOUNCER
      I'm trying to get the output data from https://www.guilded.gg but it uses a web app that generates that output on the fly and this doesn't show up in the page source.
      Only in web inspector of each browser does this data show up. How do I read this data in autoit (equivalent to the web inspector)
      thank you
    • whiskas
      By whiskas
      Hi all,
      I just upgraded to windows 10 and am using Edge as my browser now. Updated my scripts, but I can not unhide a minimized Edge window with the script anymore.
      WinSetState ( "titlle","", @SW_MAXIMIZE ) works fine, but not if it is minimized. Tried same with SW_SHOW, doesn't work.
      WinExists("title","") -> returns 1, so it is finding my window.
              If Not WinActive($title,$text) Then WinActivate($title,$text)
      Doesn't work also, so I think I tried all but cant get the window back
      Any help would be appreciated