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

    • SkysLastChance
      By SkysLastChance
      <input name="VsMasterPage$MainContent$LoginUserControl$LoginForm$FormsAuthLoginContainer$LoginButton$InternalButton" class="Button" id="VsMasterPage_MainContent_LoginUserControl_LoginForm_FormsAuthLoginContainer_LoginButton_InternalButton" onclick='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("VsMasterPage$MainContent$LoginUserControl$LoginForm$FormsAuthLoginContainer$LoginButton$InternalButton", "", true, "Login", "", false, false))' type="submit" value="Sign In"> I am trying to click the sign in button on this page. 
      I have tried by class, text, etc 
      Here was my last attempt
      $oButtons = _IETagNameAllGetCollection($o_IE, "button") For $oButton in $oButtons If String($oButton.value) = "Sign In" Then Sleep (1000) _IEAction($oButton, "click") ExitLoop EndIf Next This did not work either.
    • 5ervant
      By 5ervant
      Go create a quick account in Zapier and go to https://zapier.com/app/dashboard and make some Zaps!
      Just need to click the specific instance of an .open-menu button and then click its a.run (anchor) element.
      Doing this IE.au3 script just causing to click its container element:
      $target = 1; Target the first instance #include <IE.au3> $oIE = _IEAttach("Dashboard - Zapier") $count = 0; $tags = _IETagNameGetCollection($oIE, "div") For $tag in $tags $class_value = $tag.GetAttribute("class") If $class_value = "open-menu" Then $count += 1 if $count = $target Then MsgBox(0, "Instance: ", $count) ; $tag.fireEvent("onmousedown") ; _IEAction($tag, "click") ; $tag.fireEvent("onmouseup") ; Or this but not working ; $tag.Click EndIf EndIf Next I also tried to do it using FF.au3
      $target = 1; Target the first instance #Include <Array.au3> #Include <FF.au3> $count = 0; If _FFConnect(Default, Default, 3000) Then $aArray = _FFXPath( "//div[@class='open-menu']", "", 7 ) ; _ArrayDisplay($aArray) For $tag in $aArray $count += 1 if $count = $target Then MsgBox(0, "Instance: ", $count) _FFClick($tag) EndIf Next EndIf Error: _FFClick ==> No match: $sElement: [number]
      Could some help me how to click such buttons on such kind of a dynamic page?
    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      When I launch a URL and the webpage takes more time to load (say more than 1 minute), I want the URL to be relaunched.
      I used _IELoadWait(). But the control doesn't get pass through the _IELoadWait() command, since the webpage takes more time to load.
      I searched some of the older posts related to this topic. But I couldn't work them out.
      Please guide me.
    • elbhiri
      By elbhiri
      i have two files a.au3 and b.au3 the both contains the same code which is :
      #include <IE.au3> #include <MsgBoxConstants.au3> Global $myUrl = "https://www.autoitscript.com" RegWrite('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main','SessionMerging','REG_DWORD','00000000') ShellExecute ("iexplore.exe", " -nosessionmerging about:blank") WinWait ("Blank Page") Global $oIE = _IEAttach ("about:blank", "url") _IELoadWait ($oIE) _IENavigate ($oIE, $myUrl) when i launch the both files in the same time two blank windows are opens.
      what im waiting for is that every window navigate to the link but what happen is the first and the second file navigate the url to the same window and the seconde window stay about:blank
      i think the problem happen because i try to open the same url in both windows
      so i need i way to navigate to the same url from two different windows
      Thanks in advance
    • HudsonKane
      By HudsonKane
      I have a page with several hundred <div>s, and each <div> has several hundred child <div>s, each with their own children
      when I use _IETagNameGetCollection($ie, "div", 0) I get them all, but I need to find a way to get say the 3rd child of the 5th child of the second top level <div>
      I have not yet been able to find anything along this line
      Is there any way to determine if an element is a child, parent, sibling?
      Thank you