Rhazz

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
WinActivate($title)
If WinActive($title) Then
    send("C:\Users\myuser\images\my_image.jpg")
    Send("{ENTER}")
Else
    MsgBox($MB_SYSTEMMODAL, "WinActive", "Window not found.")
EndIf

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"
WinActivate($title)
If WinActive($title) Then
    ControlClick($title, "", 1148) ; Still it does not work
    send("C:\Users\myuser\images\my_image.jpg")
    Send("{ENTER}")
Else
    MsgBox($MB_SYSTEMMODAL, "WinActive", "Window not found.")
EndIf

 

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.

Global $EVENT_Min = $EVENT_SYSTEM_DIALOGSTART
Global $EVENT_Max = $EVENT_SYSTEM_DIALOGSTART

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


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


While 1
    Sleep(10)
WEnd



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)
         ControlSetText($hWnd,"","Edit1",$sFile)
         ControlClick($hWnd,"","Button1")
    EndIf

EndFunc   ;==>_WinEventProc

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

    Local $aRet=0
    Local Const $WINEVENT_OUTOFCONTEXT = 0x0
    Local Const $WINEVENT_SKIPOWNPROCESS = 0x2
    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, _
            "uint", BitOR($WINEVENT_OUTOFCONTEXT, $WINEVENT_SKIPOWNPROCESS))
    If @error Then Return SetError(@error, 0, 0)
    Return $aRet[0]
EndFunc   ;==>_SetWinEventHook

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

Func OnAutoItExit()
    If $hWinEventProc Then
        DllCallbackFree($hWinEventProc)
    EndIf
    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.

Saludos

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

    • FMS
      By FMS
      Hello,
      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,
      Brian
    • BOUNCER
      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.
       
              WinWait($title,$text,$timeout)
              If Not WinActive($title,$text) Then WinActivate($title,$text)
              WinWaitActive($title,$text,$timeout)
      Doesn't work also, so I think I tried all but cant get the window back
      Any help would be appreciated
       
    • dilligence
      By dilligence
      Hello everyone,
      I could use some help with the following: 
      I'm a speech recognition user and recently I've started to use AutoIt for additional scripting because sometimes it works faster. 
      I would like to create an AutoIt script that will open the Chrome link on my desktop which is a a symbolic link, so that the Chrome cache is on my Ram drive:
      "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disk-cache-dir="A:\Browser Cache"
      Next I want to send the website address, in this case: https://autochords.com/ (with SendKeys) to the address bar.
      Then another SendKeys to send Enter.
      I want to use this script when I'm working on my girlfriend's computer, where speech recognition isn't installed.
      I could use ShellExecute ("Chrome", "https://autochords.com/") but then it won't run via my ram drive.
      I am a Dragon NaturallySpeaking user. The program has a scripting language similar to VBA. In Dragon the command is as follows:
      HeardWord "open","chrome" ; HeardWord acts as if I literally said "open Chrome" this command opens any desktop shortcut no matter which window I'm working in.
      Wait 1500 
      SendKeys "https://autochords.com/"
      SendKeys "{Enter}"; these last three lines are similar to AutoIt language I think.....
      Any help would be appreciated.
      Rob