Jump to content

Using AutoIT to populate a file in an IE form


jacobp
 Share

Recommended Posts

I've been playing around with this for awhile now and it has me stumped. I'm trying to automate a webform and have been unsuccessful in editing the form input. Send is the only method that I've got working but I can't use that as the script will run in the background. My attempts at using control send failed miserably. My attempts at _IEFormElementSetValue failed as well. Can anyone offer any suggestions, direction, guidance, or direction on how I can accomplish this?

Here's the current AutoIT code I've been using.

$new_page = "http://10.131.180.109/RemoteAdmin/updateform.html"
    $tmp_page = _IECreate($new_page,0,1,0,-1)
    
    ;_IELoadWait($tmp_page,100,2000)
    $Auth_Active=winwaitactive("Connect to","",20000)
    $results=WinExists("Connect to")
    if $Auth_Active = 1 Then
        controlsend("Connect to","","Edit2","admin")
        controlsend("Connect to","","Edit3","smartlane")
        controlclick("Connect to","","Button2")
    EndIf
    _IEloadwait($tmp_page,1000,15000)

$oForms = _IEFormGetCollection ($tmp_page,0)

$oForm = _IEFormGetObjByName ($oForms, $oForms.name)

$oQuery1 = _IEFormElementGetCollection ($oForm, 0)

_ieformelementsetvalue($oQuery1,"C:\Work\Irisys\SDI_files\SmartlaneCAB.CAB",1)

I've also tried this:

$new_page = "http://10.131.180.109/RemoteAdmin/updateform.html"
    $tmp_page = _IECreate($new_page,0,1,0,-1)
    
    ;_IELoadWait($tmp_page,100,2000)
    $Auth_Active=winwaitactive("Connect to","",20000)
    $results=WinExists("Connect to")
    if $Auth_Active = 1 Then
        controlsend("Connect to","","Edit2","admin")
        controlsend("Connect to","","Edit3","smartlane")
        controlclick("Connect to","","Button2")
    EndIf
    _IEloadwait($tmp_page,1000,15000)

$oForms = _IEFormGetCollection ($tmp_page,0)

$oForm = _IEFormGetObjByName ($oForms, $oForms.name)

$oQuery1 = _IEFormElementGetCollection ($oForm, 0)
$hwnd=_IEPropertyGet($oForm,"hwnd")

controlsend($hwnd,"","","C:\Work\Irisys\SDI_files\SmartlaneCAB.CAB")

I've tried a few other things that I can't remember off the top of my head as well but to no avail. Many of the other attempts were various ways of using controlsend.

Here's the html from the page.

<form name="configForm" enctype='multipart/form-data' action='/web/SLPlugin.dll?action=UpdateSystem' onsubmit="return initReporting();" method=post>
  Please select the SDI update CAB file to upload<br />
  <br />
  <input name=cabfile id=cabfile type=file size=40 onchange='checkCAB();' /><br />
  <div id='cabError' style='color: #ff3333;'></div>
  <br />

  <input type=hidden name=submitupdate value="Upgrade SDI" />
  <div class="controls"><a href="#" class="button" onclick="initReporting();"><b><b><b>Update SDI</b></b></b></a></div>
  <br clear="both" />
</form>
Link to comment
Share on other sites

Your method for getting the Form object is screwed up. Try this, and run it from SciTE so you get any valuable error info from the console:

#include <IE.au3>

Global $sCAB, $new_page, $tmp_page, $oForm, $oInput

_IEErrorHandlerDeRegister()

$sCAB = "C:\Work\Irisys\SDI_files\SmartlaneCAB.CAB"
$new_page = "http://10.131.180.109/RemoteAdmin/updateform.html"
$tmp_page = _IECreate($new_page, 0, 1, 0, -1)
_IELoadWait($tmp_page, 1000, 15000)
$oForm = _IEFormGetObjByName($tmp_page, "configForm")
$oInput = _IEFormElementGetObjByName($oForm, "cabfile")
_IEFormElementSetValue($oInput, $sCAB)
_IEFormSubmit($oForm)

Input elements with a file type are a special case for security reasons. So if that doesn't work, try this:

#include <IE.au3>

Global $sCAB, $new_page, $tmp_page, $oForm, $oInput

_IEErrorHandlerDeRegister()

$sCAB = "C:\Work\Irisys\SDI_files\SmartlaneCAB.CAB"
$new_page = "http://10.131.180.109/RemoteAdmin/updateform.html"
$tmp_page = _IECreate($new_page)
_IELoadWait($tmp_page, 1000, 15000)
$oForm = _IEFormGetObjByName($tmp_page, "configForm")
$oInput = _IEFormElementGetObjByName($oForm, "cabfile")
_IEAction($oInput, "focus")
$hIE = _IEPropertyGet($tmp_page, "hwnd")
ControlSend($hIE, "", "", $sCAB)
_IEFormSubmit($oForm)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I appreciate your response, but neither of your methods would input any data into the box either.

The form itself it a blank text box that gets populated from a browse button. I discovered though that if I type in the local path of the file that it bypasses the browse button. Unfortunately, I've failed being able to automate either of these functions so far.

My way of grabbing the objects did seem screwed up but whenever I read them they had the correct values. When I did _IEAction($oQuery1,"click") it would work but the script would hang with the windows, Choose File diaglog box. I tried the _IEAction($oquery,"focus") but the controlsend would never send an {enter} down.

I'm really at a lose for words and gave up awhile ago. Maybe it'll come to me on Monday.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...