Jump to content

Recommended Posts

Posted (edited)

information for the file input box on a web page:

type="file"
title="Name
" size="56"
class="ms-fileinput"
id="onetidIOFile"
name="fileupload0"

Below is the code I am using, but it returns either nothing for the variable or 0 and 7 for no match found.

$attachFileInputBoxName = "fileupload0"
        $attachFileInputBoxID = "onetidIOFile"

$attachFileButton = _IEGetObjById($oIE, $attachFileButtonID)
_IEAction($attachFileButton, "click")
_IELoadWait($oIE)
$attachFileInputBox = _IEGetObjByName($oIE, $attachFileInputBoxName)
$somefile = "c:\test.xlsx"
MsgBox(0, "", $attachFileInputBox & "           " & @error)
_IEFormElementSetValue($attachFileInputBox, $somefile)

Maybe I'm just tired, but I'm not seeing why this isn't working.

Some step by step:

We go to our internal ticket page, click attach file button, it goes to a new link with the file input box and you can type in a file name or hit 'browse' and select the file yourself.

When you hit OK on that page it takes you back to the ticket and attaches the file to the bottom.

Pretty simple, but I have no idea why this code isn't working.

Edited by xeroTechnologiesLLC
Posted

Still struggling with this.

I wrote a separate script to go straight to the page and fill out the data in that one file input box and it still isn't working - it's like it it's not the right name for the element when I know the name is right.

Any ideas on this would be great.

Posted

i'm an idiot...

RTFM...

"Note: You cannot use _IEFormElementSetValue to set the value of an INPUT TYPE=FILE element. Browser security restrictions prevent this element from being scripted. See the example below for a workaround."

; *******************************************************
; Example 4 - Set the value of an INPUT TYPE=TEXT element on an invisible
;              window using ControlSend()
; *******************************************************
;
#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, "textExample")
; Assign input focus to the field and then send the text string
_IEAction($oInputFile, "focus")
; Select existing content so it will be overwritten.
_IEAction($oInputFile, "selectall")
; Get a handle to the IE window.
Local $hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "This works")
MsgBox(0, "Success", "Value set to 'This works'")
_IEAction($oIE, "visible")

So my code turns into:

$attachFileButton = _IEGetObjById($oIE, $attachFileButtonName)          ; ======attach file here
_IEAction($attachFileButton, "click")
_IELoadWait($oIE)
$attachedFile = String(GUICtrlRead($inpCscreenshot))
$fileAttachForm = _IEFormGetObjByName($oIE, "aspnetForm")
$attachFileInputBox = _IEFormElementGetObjByName($fileAttachForm, $attachFileInputBoxName)
_IEAction($attachFileInputBox, "focus")
_IEAction($attachFileInputBox, "selectall")
; Get a handle to the IE window.
Local $hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", $attachedFile)
$clickOKbtn = _IEGetObjByName($oIE, $clickOKbtnName)
_IEAction($clickOKbtn, "click")
    GUICtrlSetData($pBar1, 48.5)
    GUICtrlSetData($lblProgressStepper, "attaching file...")
    Sleep(100)

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
  • Recently Browsing   0 members

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