Jump to content

Unable to set value of IE Form element


Recommended Posts

Yes, and when I do, I get unexpected results. I posted in a previous post that when I do

$oIEcreate = _IECreate(http://localhost:1234)
$oIE = _IEFrameGetCollection($oIEcreate,1)
Local $oForms = _IEFormGetCollection($oIE,1)
Local $iNumForms = @extended
MsgBox($MB_SYSTEMMODAL, "Forms Info", "There are " & $iNumForms & " forms on this page")
Local $oForm
For $i = 0 To $iNumForms - 1
    $oForm = _IEFormGetCollection($oIE, $i)
    MsgBox($MB_SYSTEMMODAL, "Form Info", $oForm.id)
Next  

It does sees two forms and the name of one of the forms (the one I expect... auth_form).

I did try using that in my base code, but it still fails to fill out the form.

Link to comment
Share on other sites

Local $oIE_open = _IECreate("http://localhost:1234")
Local $oIE=_IEFrameGetCollection($oIE_open, 1)
$o_form = _IEFormGetObjByName($oIE, "form_auth")
$o_login = _IEFormElementGetObjByName($oIE, "usuario")
$o_password = _IEFormElementGetObjByName($oIE, "password")
; Set field values and submit the form
_IEFormElementSetValue($o_login, $saved_un1)
_IEFormElementSetValue($o_password, $saved_pw1)

and the console output

 

--> IE.au3 T3.0-0 Warning from function _IEFormGetObjByName, $_IEStatus_NoMatch

--> IE.au3 T3.0-0 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidObjectType
--> IE.au3 T3.0-0 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidObjectType
--> IE.au3 T3.0-0 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType
--> IE.au3 T3.0-0 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType
Link to comment
Share on other sites

Ok... run this and then post the console output:

#include <IE.au3>

Local $oIE = _IECreate("http://localhost:1234)
Local $oFrame = _IEFrameGetCollection($oIE, 1)
Local $oForms = _IEFormGetCollection($oFrame)

ConsoleWrite("There are " & @extended & " form(s) on this page" & @CRLF)

For $oForm In $oForms
    ConsoleWrite("Form Info: " & $oForm.name & @CRLF)
Next
Link to comment
Share on other sites

Apparently I forgot to post this:

>Running:(3.3.10.2):C:UsersarudolphDesktopAutoit - Portableautoit-v3installautoit3.exe "C:UsersarudolphDesktopdeleteme.au3"   

--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop

there are 1 form(s) on this page

Form info: 0

+>12:44:27 AutoIt3.exe ended.rc:0

+>12:44:27 AutoIt3Wrapper Finished.

>Exit code: 0    Time: 0.5946

Link to comment
Share on other sites

  • 3 weeks later...

What have you tried in the past two weeks?

Run the following and post the results from the Scite output window:

#include <IE.au3>

Local $oIE = _IECreate("http://localhost:1234")
Local $oFrame = _IEFrameGetCollection($oIE, 1)
Local $oForm = _IEFormGetCollection($oFrame, 0)
Local $oText = _IEFormElementGetObjByName($oForm, "usuario")
_IEFormElementSetValue($oText, "Hey! This works!")
Link to comment
Share on other sites

I've been trying to use Mouse clicks based on vector, but if you resize the window, it causes issues. I haven't been able to figure out how to bind to the element itself because it doesn't have a name..

 

Here is the output from the console

>Running:(3.3.10.2):C:Usersx345705DesktopAutoit - Portableautoit-v3installautoit3.exe "C:Usersx345705Desktopdeleteme.au3"   

--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop

--> IE.au3 T3.0-0 Warning from function _IEFormGetCollection, $_IEStatus_NoMatch

--> IE.au3 T3.0-0 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidDataType

--> IE.au3 T3.0-0 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType

+>14:12:37 AutoIt3.exe ended.rc:0

+>14:12:37 AutoIt3Wrapper Finished.

>Exit code: 0    Time: 1.729

Edited by Jewtus
Link to comment
Share on other sites

This doesn't make any sense. In post 27 we proved that there is 1 form in the frame. So how can the call to _IEFormGetCollection fail?

You have the rest of us flying blind here. You are in the best position to solve the problem because you are the only one with access to the website. Forget the mouse clicks. Focus on using the IE functions. Figure out step by step how to access the desired form elements. Look at the source of the web page. Are we accessing the correct frame?

Also, I noticed in post #9 that there is a message at the bottom of the screenshot stating that IE has blocked the webpage from running scripts. Could this be impacting your script?

Link to comment
Share on other sites

  • 3 weeks later...

From what I can see, your one example would work if you update the get object to use the form object instead of the IE object...

you posted this...

Local $oIE_open = _IECreate("http://localhost:1234")
Local $oIE=_IEFrameGetCollection($oIE_open, 1)
$o_form = _IEFormGetObjByName($oIE, "form_auth")
$o_login = _IEFormElementGetObjByName($oIE, "usuario")
$o_password = _IEFormElementGetObjByName($oIE, "password")
; Set field values and submit the form
_IEFormElementSetValue($o_login, $saved_un1)
_IEFormElementSetValue($o_password, $saved_pw1)

But instead, try this...

Local $oIE_open = _IECreate("http://localhost:1234")
Local $oIE=_IEFrameGetCollection($oIE_open, 1)
$o_form = _IEFormGetObjByName($oIE, "form_auth")
$o_login = _IEFormElementGetObjByName($o_form, "usuario")
$o_password = _IEFormElementGetObjByName($o_form, "password")
; Set field values and submit the form
_IEFormElementSetValue($o_login, $saved_un1)
_IEFormElementSetValue($o_password, $saved_pw1)

Also,

While this would definately fix the form element object call because you did not point it to the form object, it won't fix the fact that the form object itself is still "unknown".  so you will have to figure out with frame to attach these calls too.  I've had this every issue myself, and still have it on some cases, still seeking assistance, but in this case, you have to point it to the proper frame, or it won't work. 

I have a little sub function I use to get frame and form. (if you know their names)...

Func _GetFF(ByRef $o_objectHWND,$o_IFrame,$o_Form)
    Local $oIE1,$oIFrame1,$oForm1
    $Count = 0
    Do
        $Count+=1
        $oIE1 = _IEAttachHWND($o_objectHWND)
        Sleep(300)
        If $Count > 25 Then
            MsgBox(0,$FTMerror1,$FTMerror2)
            Return SetError($_IEStatus_NoMatch, 1, 0)
        EndIf
    Until IsObj($oIE1)
    Sleep(300)
    $Count = 0
    Do
        $Count+=1
        $oIFrame1 = _IEFrameGetObjByName($oIE1, $o_IFrame)
        If @error Then Return
        Sleep(300)
        If $Count > 25 Then
            MsgBox(0,$FTMerror1,$FTMerror2)
            Return SetError($_IEStatus_NoMatch, 2, 0)
        EndIf
    Until IsObj($oIFrame1)
    Sleep(300)
    $Count = 0
    Do
        $Count+=1
        $oForm1 = _IEFormGetObjByName($oIFrame1, $o_Form)
        If @error Then Return
        Sleep(200)
        If $Count > 20 Then
            MsgBox(0,$FTMerror1,$FTMerror2)
            Return SetError($_IEStatus_NoMatch, 3, 0)
        EndIf
    Until IsObj($oForm1)
    sleep(300)
    Return SetError($_IEStatus_Success, 0, $oForm1)
EndFunc

Here I send the frame name and form name down to the function, then I have a form object to use.  might not be the best way, but for my company's site, as sluggish as it is, I had to code in the "Do...Until" to keep trying.

oh, and the _IEAttachHWND($o_objectHWND) is just a custom quick from of IEattach, but this one only attaches by the hwnd item.  so you can substitute IEAttach there, and use the hwnd of the IE object and use the comma ,"hwnd".

 

Hope some of this helps or makes sense.

Thanks.

Edited by kalel69
Link to comment
Share on other sites

Thanks for the suggestions. I tried your tweak, but I still get an error returned from the _IEFormGetCollection (I get the same $_IEStatus_NoMatch error).

When I tried your subfunction, I get errors:

_IEAttachHWND gives me an undefined function

and

$FTMerror1 and 2 are not defined.

What are you using for includes?

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

×
×
  • Create New...