Jump to content

Recommended Posts

Posted

I'm usting AutoIt (with IE.au3) to automate web test.

The web page I'm testing has an input of type "file", by performing a click on it, a "Choose file" window will show up; and it seems that my script will be blocked at this point till the "Choose file" window disappears by some manual input.

I tried WinWaitActive to wait for the "Choose file" window right after the click, but failed.

What I want is to let the script finish the inputs in "Choose file" window. Anyone would like to provide a solution for this situation?

Thanks!

Posted (edited)

; *******************************************************

; Example 5 - Set the value of an INPUT TYPE=FILE element

; Same as previous example, but with invisible window

; (security restrictions prevent using _IEFormElementSetValue)

; *******************************************************

;

#include <IE.au3>

$oIE = _IE_Example("form")

; Hide the browser window to demonstrate sending text to invisible window

_IEAction($oIE, "invisible")

$oForm = _IEFormGetObjByName($oIE, "ExampleForm")

$oInputFile = _IEFormElementGetObjByName($oForm, "fileExample")

; Assign input focus to the field and then send the text string

_IEAction($oInputFile, "focus")

$hIE = _IEPropertyGet($oIE, "hwnd")

ControlSend($hIE, "", "Internet Explorer_Server1", "C:\myfile.txt")

MsgBox(0, "Success", "Value set to C:\myfile.txt")

_IEAction($oIE, "visible")

Edited by mikehunt114
IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Posted

Thanks for your reply!

I tried the example but failed because ControlSend will return 0 indicating a failure.

$oInputFile = _IEFormElementGetObjByName($oForm, "fileExample")

; Assign input focus to the field and then send the text string
_IEAction($oInputFile, "focus")
$hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "Internet Explorer_Server1", "C:\myfile.txt")

In fact I also tried _IEFormElementSetValue, failed too :)

$oInputFile = _IEFormElementGetObjByName($oForm, "fileExample")

_IEFormElementSetValue($oInputFile, "C:\myfile.txt")

Here _IEFormElementSetValue will lead to an error: "--> IE.au3 Error from function _IEFormElementSetValue, $_IEStatus_InvalidObjectType (Browser securuty prevents SetValue of TYPE=FILE)"

Any ideas? Thanks!

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
×
×
  • Create New...