Jump to content

Unable to set value of IE Form element


Recommended Posts

I'm trying to adapt the example

#include <IE.au3>

Local $oIE = _IE_Example("form")
Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm")
Local $oText = _IEFormElementGetObjByName($oForm, "textExample")
_IEFormElementSetValue($oText, "Hey! This works!")

to work with a log in page and I'm not sure what I'm doing wrong and why its acting up.

This is what I tried:

#include <IE.au3>

Local $oIE = _IEAttach("C:\Test.html","Windowtitle")
Local $oForm = _IEFormGetObjByName($oIE, "form_auth")
Local $oText = _IEFormElementGetObjByName($oForm, "usuario")
_IEFormElementSetValue($oText, "Hey! This works!")

but it doesn't fill out the form.

Here is a snippet of the HTML of the form I'm working with:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<body>
<div class="opLogonBody">
<div class="left">
    <div class="opLogonComponent">

<div id="auth" class="security">
<form id="form_auth" action="BtoChannelDriver.ssobto?dse_contextRoot=true" method="post"  >
<div class="body">
<div class="superior">
<fieldset class="identificacion" id="identificacion"><legend>Data</legend>
<p>Please enter your logon information and press "Send"</p>
<div class="row"><label for="id_1">User:</label><input name="usuario" type="text" id="id_1"  maxlength="50" onfocus="idToWrite=&#9;id_1&#9;;pos=null" /></div>
<div class="row"><label for="clave">Password:</label><input type="password" name="password" id="clave"   maxlength="30" onfocus="idToWrite=&#9;clave&#9;;pos=null"/></div>
</fieldset>
</div>
</div>
<div class="foot"><span class="buttons"><input type="submit" value="Send"/></span><span class="link"><a href="" id="id_authenticateLink"></a></span></div>
</form>
</div>


    </div>
   </div>
</div>
</body>
</html>

Anyone know why it is not filling out the form?

Link to comment
Share on other sites

This happens when I use IEcreate as well. 

#include <IE.au3>

Local $oIE = _IECreate("http://localhost:1234/test.html")
Local $oForm = _IEFormGetObjByName($oIE, "form_auth")
Local $oText = _IEFormElementGetObjByName($oForm, "usuario")
_IEFormElementSetValue($oText, "Hey! This works!")

If I was using attach incorrectly, so be it, but I don't actually care about the attach function. I saw trying to make it simpler so people don't have to save the HTML and load it into IIS. I tried IE create on a file path and it doesn't work, hence the use of IEAttach.

Edited by Jewtus
Link to comment
Share on other sites

 

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:UsersArudolphDesktopNew AutoIt v3 Script.au3" /UserParams    

+>13:32:20 Starting AutoIt3Wrapper v.2.2.0.0 SciTE v.3.4.1.0   Keyboard:00000409  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0409)
+>         SciTEDir => C:Program Files (x86)AutoIt3SciTE   UserDir => C:UsersArudolphAppDataLocalAutoIt v3SciTEAutoIt3Wrapper   SCITE_USERHOME => C:UsersArudolphAppDataLocalAutoIt v3SciTE 
>Running AU3Check (3.3.10.2)  from:C:Program Files (x86)AutoIt3  input:C:UsersArudolphDesktopNew AutoIt v3 Script.au3
+>13:32:21 AU3Check ended.rc:0
>Running:(3.3.10.2):C:Program Files (x86)AutoIt3autoit3.exe "C:UsersArudolphDesktopNew AutoIt v3 Script.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
--> IE.au3 T3.0-1 Error from function _IELoadWait, $_IEStatus_InvalidObjectType ()
--> IE.au3 T3.0-1 Warning from function _IEFormGetObjByName, $_IEStatus_NoMatch
--> IE.au3 T3.0-1 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidDataType
--> IE.au3 T3.0-1 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType
+>13:32:22 AutoIt3.exe ended.rc:0
+>13:32:22 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.885
 
Link to comment
Share on other sites

try this

Local $oIE = _IECreate("c:\test.html")
_IELoadWait($oIE) ; allows webpage to fully load before proceding
Local $oForm = _IEFormGetObjByName($oIE, "form_auth")
Local $oText = _IEFormElementGetObjByName($oForm, "usuario")
_IEFormElementSetValue($oText, "Hey! This works!")

adding _IELoadWait may help

shaggy

Link to comment
Share on other sites

Ok... so the call to _IECreate failed. Did the web page load? You need to help yourself by providing more details so that we can help you.

Yes, the IE window does show up but nothing gets entered into the form itself.

 

I don't believe adding another call to _IELoadWait will change anything (there is an inherent one in the _IECreate call).

When I run the code, it works as expected. The OP will need to provide more information in order to troubleshoot the issue.

I tried adding the IEloadwait and that didn't do anything. If it is working for you, I wonder if I have a corrupt IE.au3 script...

For more context:

When I run this script, IE pops up and then nothing else happens (his is what the IE window looks like when I run the script).

15cem4p.png

Edited by Jewtus
Link to comment
Share on other sites

Am not sure what you are doing wrong, but I just tried the script you posted using the HTML snippet, and it worked after I gave the webpage a title to attach to..

#include <IE.au3>

Local $oIE = _IEAttach("Hello World")
Local $oForm = _IEFormGetObjByName($oIE, "form_auth")
Local $oText = _IEFormElementGetObjByName($oForm, "usuario")
_IEFormElementSetValue($oText, "Hey! This works!")

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<title>Hello World</title>
<body>
<div class="opLogonBody">
<div class="left">
    <div class="opLogonComponent">

<div id="auth" class="security">
<form id="form_auth" action="BtoChannelDriver.ssobto?dse_contextRoot=true" method="post"  >
<div class="body">
<div class="superior">
<fieldset class="identificacion" id="identificacion"><legend>Data</legend>
<p>Please enter your logon information and press "Send"</p>
<div class="row"><label for="id_1">User:</label><input name="usuario" type="text" id="id_1"  maxlength="50" onfocus="idToWrite=&#9;id_1&#9;;pos=null" /></div>
<div class="row"><label for="clave">Password:</label><input type="password" name="password" id="clave"   maxlength="30" onfocus="idToWrite=&#9;clave&#9;;pos=null"/></div>
</fieldset>
</div>
</div>
<div class="foot"><span class="buttons"><input type="submit" value="Send"/></span><span class="link"><a href="" id="id_authenticateLink"></a></span></div>
</form>
</div>


    </div>
   </div>
</div>
</body>
</html>

Link to comment
Share on other sites

Am not sure what you are doing wrong, but I just tried the script you posted using the HTML snippet, and it worked after I gave the webpage a title to attach to..

#include <IE.au3>

Local $oIE = _IEAttach("Hello World")
Local $oForm = _IEFormGetObjByName($oIE, "form_auth")
Local $oText = _IEFormElementGetObjByName($oForm, "usuario")
_IEFormElementSetValue($oText, "Hey! This works!")

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<title>Hello World</title>
<body>
<div class="opLogonBody">
<div class="left">
    <div class="opLogonComponent">

<div id="auth" class="security">
<form id="form_auth" action="BtoChannelDriver.ssobto?dse_contextRoot=true" method="post"  >
<div class="body">
<div class="superior">
<fieldset class="identificacion" id="identificacion"><legend>Data</legend>
<p>Please enter your logon information and press "Send"</p>
<div class="row"><label for="id_1">User:</label><input name="usuario" type="text" id="id_1"  maxlength="50" onfocus="idToWrite=&#9;id_1&#9;;pos=null" /></div>
<div class="row"><label for="clave">Password:</label><input type="password" name="password" id="clave"   maxlength="30" onfocus="idToWrite=&#9;clave&#9;;pos=null"/></div>
</fieldset>
</div>
</div>
<div class="foot"><span class="buttons"><input type="submit" value="Send"/></span><span class="link"><a href="" id="id_authenticateLink"></a></span></div>
</form>
</div>


    </div>
   </div>
</div>
</body>
</html>

That is strange... I just added the title as well and the attach call works. I'm not sure why it would be failing in the create call though...

Link to comment
Share on other sites

Unfortunately using the attach function didn't work on the site I'm trying to setup an auto login for. Anyone have any suggestions for how to setup an alternative auto login script against this?

Link to comment
Share on other sites

Its an internal site for my company (it has client and employee data so the information is secure). They wont grant direct DB access which is why I have to go through the portal in the first place. Thanks anyway everyone.

Link to comment
Share on other sites

I stumbled across one of the problems... but not sure its the root cause.

When I get the form from the actual website, doesn't see a form. I was using example 3 of _IEFormGetCollection and I replaced the URL. When I did, the pop up said this page has 0 forms. I change the index to 1 and then it said there was 1 form, but it didn't output the name (like it did when I tried it against _IE_Example("form"))

How can I convert an object into something that I can look at to see what is going on... maybe dump it to a text file or something?

Link to comment
Share on other sites

No iframes, but there are a number of scripts on the page (unfortunately, not ones I can share for security reasons). This is a screenshot of the basic HTML and how its structured.

Basically there is a HTML wrapped piece of HTML... its weird.

2efpd20.jpg

Link to comment
Share on other sites

I tried this:

Local $oIEattach = _IEAttach("Hello World")
local $oIE = _IEFrameGetObjByName($oIEattach, "___nav___"
;local $oIE = _IEFrameGetCollection($oIEattach, 1)
Local $oForm = _IEFormGetObjByName($oIE, "form_auth")
Local $oText = _IEFormElementGetObjByName($oForm, "usuario")
_IEFormElementSetValue($oText, "Hey! This works!")

I tried using get collection and using the name, but both ways still dont seem to work.

The console output is still saying that the _IEFormGetObjByName is getting no match. 

When I do this:

$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 detect the form, and it displays the form name. When I swap out the IEFrame with this one:

$oIE = _IEFrameGetObjByName($oIEcreate,"___nav___")

It fails to pull up the name but it does show up with the same count of forms.

I’m missing something fundamental here I think. When I comment out Local $oForms = _IEFormGetCollection($oIE,1) I get the following error

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

"C:Usersx345705DesktopDeleteme.au3" (29) : ==> Variable must be of type "Object".:

MsgBox(0,"SHOWUP",$oForm.id)

MsgBox(0,"SHOWUP",$oForm^ ERROR

 

And it kicks up a count of two forms as well as the name of the form.

So I tried tweaking it a little bit:

$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(0,"SHOWUP",$oForm.id)
Next

I get --> IE.au3 T3.0-0 Warning from function _IEFormGetCollection, $_IEStatus_NoMatch (which is likely because the first “form” doesn’t have a name..)

When I comment out the first msg box and run the script, no dialogs pop up. It’s like the first msgbox makes the script kick something up, but I’m getting really confused at this point.

Any suggestions?

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...