Sign in to follow this  
Followers 0
Jewtus

Unable to set value of IE Form element

33 posts in this topic

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?

Share this post


Link to post
Share on other sites



Reread the _IEAttach for a start.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
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
 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Share this post


Link to post
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>

Share this post


Link to post
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...

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

What site?

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Are there any iFrames involved?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

The page contains frames. You need to first use _IEFrameGetObjByName to retrieve a reference to the desired frame. The use this reference in the _IEFormGetObjByName command instead of $oIE.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Are you sure that you have the correct frame? Generally, there will be more than one and I wouldn't expect a "nav" frame to hold the input forms. I would suggest looking at the example code for _IEFrameGetCollection and try running it against your web page. Post the results here.

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • kawliga751
      By kawliga751
      I am trying to script the opening of multiple tabs in IE with each tab having a separate login/password. I have been able to make a successful script that will open 3 separate IE sessions with the correct webpage and login or a script that will open 3 tabs in one session (which I want) but will not login. I have tried _IECreate, IEAttach etc. This is the script I am currently using . 
      #include <IE.au3> Const $navOpenInNewTab = 0x0800 Dim $oIE = _IECreate('http://asag.xxxxxxx.com/AAAA/index.htm') ;$o_IE.Navigate2('http://asag.xxxxxxx.com/apps/yyyyyyy/LogInSAG/login.asp', $navOpenInNewTab) ;$o_IE.Navigate2('http://asag.xxxxxxx.com/apps/yyyyyyy/LogInSAG/login.asp', $navOpenInNewTab) Call ("YYYYYYYSignIn") Func YYYYYYYSignIn () Local $username = _IEGetObjByName ($oIE,"uname") Local $password = _IEGetObjByName ($oIE,"pword") $oIE.Navigate2('http://asag.xxxxxxx.com/apps/xxxxxxx/LogInSAG/login.asp',2048) _IEFormElementSetValue ($username, "xxxxxxx") _IEFormElementSetValue ($password, "xxxxxxx") Send('{Enter}') EndFunc Call ("xxxxxxxSignIn") Func xxxxxxxSignIn () __IENavigate($oIE, "https://soa1gui.xxxxxxx.biz/gateway/NFServlet;jsessionid=1E3B8F6520DE0A1EC914A8ABB7E86341?NFH_MessageId=&NFH_Page=%2fpages%2fsearch%2fsearch.jsp", 1, 0x800) Local $domain = _IEGetObjByName ($oIE,"NF_CustomerID") Local $User_Name = _IEGetObjByName ($oIE,"NF_UserName") Local $Password = _IEGetObjByName ($oIE,"NF_Password") _IEFormElementSetValue ($domain, xxxxxxx") _IEFormElementSetValue ($User_Name, "xxxxxxx") _IEFormElementSetValue ($Password, "xxxxxxx") ;Send('{Enter}') EndFunc  
    • slidy56fr
      By slidy56fr
      Internet Explorer 11, AutoIt 3.3.14.2
      I want to download many files which are published with hyperlink on a web page. I use AutoIt and when there is a few files, it works even if It's on a website with secured links.
      I have a script to download link items with the object method (I gave a partial sample), but when the number of link exceed the web page, there is not an auto scroll, then the links which are not on displayed without scroll are not downloaded.
      Thank you
      From France
       
       
      EchantillonRecepAnonym.au3
    • SkysLastChance
      By SkysLastChance
      I am not sure on how to grab the innertext I want. Is there a way I can just grab the second line, or is there a better way to do it all together? 
      #include <IE.au3> $oIE = _IEAttach("Form Details") $oDiv = _IEGetObjById($oIE, "Col3") ;Phone MsgBox (0,"Oops",$oDiv.outertext) When I use this code I get

       


       
      html.au3
    • anthonyjr2
      By anthonyjr2
      I have come across a weird issue that I am not sure how to solve. For some reason, whenever I call WinActivate in certain scenarios instead of opening the single window that already exists, it will create a new blank tab. It should be able to be recreated with this:
      AutoItSetOption("WinTitleMatchMode", 2) Sleep(1000) For $i=0 To 10 WinActivate("Internet Explorer") Next I am not actually doing this in my code, it is just to demonstrate the fact that new tabs keep popping up. Does anyone know why this happens?
       
      EDIT: So I am not sure how reproducible this is, because it only happens every once in a while for me. I will update with more info if I find out anything.
    • SkysLastChance
      By SkysLastChance
      #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreate("website") Local $oForms = _IEFormGetCollection($oIE) For $oForm In $oForms MsgBox($MB_SYSTEMMODAL, "Form Info", $oForm.name) _IEImgClick($oForm.name, "Reserved.ReportViewerWebControl.axd?OpType=Resource&amp;Version=12.0.5522.0&amp;Name=Microsoft.ReportingServices.Rendering.HtmlRenderer.RendererResources.TogglePlus.gif", "src") Next I am having trouble clicking an image. Here is what I have tried.