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

    • 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

       
    • anthonyjr2
      By anthonyjr2
      I have come across a weird issue that I am not sure how to solve. For some reason, whenever I call WinActivate in certain scenarios instead of opening the single window that already exists, it will create a new blank tab. It should be able to be recreated with this:
      AutoItSetOption("WinTitleMatchMode", 2) Sleep(1000) For $i=0 To 10 WinActivate("Internet Explorer") Next I am not actually doing this in my code, it is just to demonstrate the fact that new tabs keep popping up. Does anyone know why this happens?
       
      EDIT: So I am not sure how reproducible this is, because it only happens every once in a while for me. I will update with more info if I find out anything.
    • zuliasro
      By zuliasro
      Hi,
      Please help me I haven't a big experience with AutoIt and JS.
      I develop a macro in AutoIt which open a Chrome browser, navigate between websites clicking no some links, insert data to forms, etc...
      Now I can't click on an element:
      <a class="mr-link js-click-link" style="font-size:16px; line-height:21px;"><u>Click now</u></a> Please pointing me how it's possible. 
      Thank you
    • zuliasro
      By zuliasro
      Hi,
      Please help me I haven't a big experience with AutoIt and JS.
      I develop a macro in AutoIt which open a Chrome browser, navigate between websites clicking no some links, insert data to forms, etc...
      Now I can't click on an element:
       
      <a class="mr-link js-captcha-link" style="font-size:16px; line-height:21px;"><u>Введите код с картинки</u></a> Please pointing me how it's possible. 
      Thank you